Compacting and Non-compacting Collections algorithms


Compacting and Non-compacting Collections algorithms

Compacting
Once garbage collector decides which objects are Alive and which objects are garbage. It moves all the Live objects at a one place in memory and reclaiming the free continuous memory area. Advantage of this is garbage collector does not need to trip around the memory for free memory area. Just increment the pointer to the next memory location and it will get the free memory location.

Non-compacting
while in non-compacting collection garbage collector does not move the live object at any place. Instead the free memory is in-place from where the object is collected for garbage. So, in this algorithm there is no probability of continuous free memory availability. So, for memory allocation garbage collector need to traverse whole memory for free sequential memory locations and it is time consuming.