Mark and sweep collectors must trace the live objects and collecting the dead objects so the cost is proportional to the size of the heap. They also suffer from fragmentation. Current research is attempting to reduce the costs by clever implementations. A variation of the mark and sweep collector which solves the fragmentation problem is the mark and compact collector. After the live objects have been marked, the objects are compacted by moving together at one end of the heap until all the live objects are contiguous.
Fragmentation is eliminated and allocation is simplified.
In addition, objects are clustered which reduces the size of the working set and improves the locality of reference over mark and sweep collection. However, the collector suffers from repeated passes over the heap as it marks the live objects, computes the new locations, moves the objects and updates pointers. Thus the algorithm may be significantly slower than the mark and sweep collector. 2.4 Copying Collection Copying collectors integrate the phases of the mark and compact collector so that only one pass over the live objects is needed. Live objects are copied from one location to another and the remaining memory is considered reclaimed.