web analytics

Garbage Collection

Garbage collection. What you get from the title of the topic? Well, while we are coding we use variable or memory location. We may need an array initially for storing some initial elements, then we take more arrays while we are manipulating. At some part of the manipulation, it may that we dont need the initial array anymore. I mean it may that we have already took all the elements of the initial array and processed and stored them in another array for furthur processing and dont need the initial array anymore. However, that initial array still remains eating up some memory locations.

However, todays higher level OOP based languages like JAVA has its own feature of freeing-up memory called garbage collection.
Actually, whenever a memory location is no more referenced (that is, used) from a program the garbage collector frees up the memory location and returns it to the memory system. It is a feature of Memory Management. We can also deallocate memory with codes. So garbage collection is a great feature.
Its not easy for programmer that S/He will concentrate on parts of the program where a variable is getting out of use and S/He will write code for deleting those. Thats why garbage collection is very important and necessary.

From Wikipedia (Link to the Complete Post):

      In computer sciencegarbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. Garbage collection was invented by John McCarthy around 1959 to solve problems in Lisp.

2 thoughts on “Garbage Collection”

  1. The concept of garbage collection doesn't exist in C++. What you are explaining is allocating memory on the stack, which is automatically "deallocated" when going out of scope.
    Garbage collection refers to the concept of removing unreferenced objects form memory (heap) regardless of the current program scope.

  2. Thank you very much. I did mixed memory deallocation with garbage collection. I have edited the post as you can see, please let me know if there is anything else wrong you find. Thanks a lot again..

Comments are closed.

Scroll to Top