Tuesday, June 05, 2007

Compacting algorithms

Tracing
algorithms result in a fragmented heap, because objects that are
garbage collected in the sweep phase, usually occupy arbitrary
positions in the heap, resulting in holes, wherever the old objects
were garbage collected. Compacting algorithms have a modified sweep
phase, in which all live objects are copied into one end of the heap.
After they are copied, the rest of the heap is freed. This places all
live objects contiguously, and the heap is defragmented.





Advantages:



  • The memory is defragmented in the sweep phase



Disadvantages:



  • The [Java] program has to be paused when the garbage collector starts.

  • References have to be updated when the live objects are moved.



Discuss this post in the learning forum.

Commercial Links



Note: This text was originally posted on my earlier blog at http://www.adaptivelearningonline.net

No comments: