Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The task of a garbage collector is to find objects that are no longer being used by a running program and deallocate them—return the their bytes to the heap so that the bytes can be reused.
Garbage collection is simple in principle. Any object that is known to be in use or can be reached by following a chain of references (pointers) from an object known to be in use is considered to be “live.” All other objects are considered to be “garbage” and are collected. The memory used by the garbage objects is returned to the heap.