Waste - Wikipedia

Advantages and disadvantages of garbage collection

Garbage Collection / January 29, 2023

Take it from a C programmer ... it is about cost/benefit and appropriate use

The garbage collection algorithms such as tri-color/mark-and-sweep there is often significant latency between a resource being 'lost' and the physical resource being freed. In some runtimes the GC will actually pause execution of the program to perform garbage collection.

Being a long time C programmer, I can tell you:

a) Manual free garbage collection is hard - This is because there is usually a greater error rate in human placement of free calls than GC algorithms.

b) Manual free garbage collection costs time - Does the time spent debugging outweigh the millisecond pauses of a GC? It may be beneficial to use garbage collection if you are writing a game than say an embedded kernel.

But, when you can't afford the runtime disadvantage (right resources, real-time constraints) then performing manual resource allocation is probably better. It may take time but can be 100% efficient.

Try and imagine an OS kernel written in Java? or on the .NET runtime with GC ... Just look at how much memory the JVM accumulates when running simple programs. I am aware that projects exist like this ... they just make me feel a bit sick.

Just bear in mind, my linux box does much the same things today with 3GB RAM than it did when it had 512MB ram years ago. The only difference is I have mono/jvm/firefox etc running. The business case for GC is clear, but it still makes me uncomfortable alot of the time.

Source: stackoverflow.com