The operating system of a computer collects all the deleted space into the free storage list periodically: The technique of this collection process is called garbage collection. It is a form of automatic memory management.
Garbage collection process usually takes place in two steps. First, the computer runs through all lists, tagging those cells that are being used & then the computer runs through the memory to collect all untagged spaces into the free-storage list. The basic principles of garbage collection are to find data objects in a program that cannot be accessed in the future and to reclaim the resources used by those objects. The garbage collector’s optimizing engine determines the best time to perform a collection, based upon the allocations being made.
The garbage collection process takes when there is only some minimum amount of space remaining or there is no space left in the free storage list or when the CPU is ILDE & has enough time to do the collection. Languages that use garbage collection are often interpreted or run within a virtual machine like the JVM. Normally, it has certain disadvantages, including consuming supplementary resources, performance impacts, probable stalls in program implementation, and inappropriateness with manual resource administration.