Garbage Collection or Garbage Accumelation?

It seems the trend nowadays is to use Java style garbage collection for all sorts of memory allocations, which makes life easier for the programmer, but does that mean it’s the right approach?

Let’s first compare garbage collection to a real world example: garbage collection! In real world you don’t go to the garbage dump every time you are done with a piece of paper, instead you keep them in a small bin under your desk, then when the bin is full you dump it all at once; obviously more efficient than cleaning your garbage after every operation. But is this really how garbage collection works in modern programming languages? Almost, except that they keep the garbage on the desk, mixed with needed papers! As long as there is empty space on the desk we dont need to perform garbage collection. This could be more efficient if you are very busy and you know your task will be quite short after which you can dump the whole thing, like in a web server, but not if you are a regular user because, first, your desk will look messy 99% of the time, second, you will need more time to start any task since you will need to perform some cleaning at the beginning of each. Maybe this is why Windows always seems to be low in memory and usually takes a considerable amount of time to launch an app even if the app looks so small!

Microsoft came up with the slogan: unused memory is wasted memory, and unfortunately a lot of people have fallen into this. Really, how does filling your memory with garbage make it not wasted?! When a user buys an additional memory we should assume his intention is to fill it with data, not to give it to us to use as a garbage bin.

So what’s the solution? The solution is obviously to give the programmer more control, and more responsibility. A balance between the completely manual allocation process of C and the completely automated process of garbage collection can save the user a lot of wasted memory and a lot of unneeded memory defragmentation. Yes, it will be a bit more work on the programmer, but I think it will be a good balance between code efficiency and implementation efficiency.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *