Last updated on June 13th, 2020 at 08:49 pm
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.
While we dont need them, we should delete them and free up memory.
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 science, garbage 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.
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.
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.