Next | Prev | Up

What is a copying collector?

In a copying garbage collector the algorithm works by starting with the roots and copying each object that is reachable to a new place in memory. As an object is copied, the pointer to where it was is updated to its new address, and a forwarding pointer is left in the old copy, so that other pointers to the object can be redirected (like leaving a mail-forwarding address behind when you move house).

All the objects that are moved have to have their contents scanned to fix-up pointers inside them (this may trigger the copying of more objects), and eventually every reachable object will get copied and scanned until no un-forwarded are left to scan.

This means that the area of memory from which objects were copied is now completely garbage and can be recycled en-masse. Also during the process of copying any fragmentation of live objects will be eliminated.

Further benefit results from the fact that objects are copied in an order that depends on which objects refer to which. With careful coding this can mean that related objects tend to be copied together, and tend to end up on the same memory page (an efficiency boost under virtual memory).



Last updated by Tue 16 January 1996