Taken from wikipedia, url: https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
“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”
The above definition says all. If you are not dealing with the actual memory in programming then I believe this is enough to know about the GC. Of course other stuff will be mentioned.
When I was answering questions in the C# section at Daniweb I often encountered the word GC. Some users always said things like: “when the garbage collector kicks in”. This get’s us to a new question and that is, when does the garbage collector really kick in?
The garbage collector (consider it being a program) kicks in, acts, get’s in charge of things when the heap gets full. This means when there is no place left for a new object to populate the heap. Please do not take this for granted, this is just for better understanding when the garbage collector does it’s job. For more on the garbage collector and heaps generation please read the first paragraph on stack-overflow first answer: click here
In real life, We cannot and we should not predict when the garbage collector starts making the free space for new objects. You can also conclude by this that it isn’t necessary to tell the garbage collector when to start (previous to the garbage collector implementation memory had been manually deallocated).
The biggest advantage of the GC is that you don’t need to deallocate objects manually, you don’t have to worry how many objects could the user create at some time and how you should take care of them (how to free space for the new objects and which objects already in action should be pushed aside to the next generation heap).
The disadvantage of the GC is that it also takes up space, it consumes resources and affects performance. In some previous versions of GC the problem was the so called “blockage/stalls” which meant that the GC rests, doesn’t do anything at some time which obviously isn’t good and affects performance.
Nowadays the GC tries to do as much work as possible in the background while the application runs, although the GC is much more sophisticated than before, it is still hard to maintain lot of memory taken by objects on the heap.
Just to mention that IOS does not implement a GC although being the most desirable. The claim that it affects their performance drastically.
Also there is something called as a Tracing garbage collection which represents a type of garbage collector which job is to trace the objects who will have to be removed by the main GC.