Navigation

Thursday, 30 January 2014

What is Garbage Collector Compaction in Java?


Compaction means moving objects in RAM so that objects become contiguous in RAM.
There are some cases when you will get out of memory error without any memory leak . And there may be memory available but there is no place for new object because of no  contiguous availability of memory. The algorithmic difficulty in a compaction algorithm is about updating all pointers, so that they point to the new object location. GC works preferentially with young objects only. Here, this means compacting only the end of the heap. full compaction being applied  rarely.  .Lets see with an example :-
Garbage Collector Compaction in Java
Garbage Collector Compaction in Java


 The point here is that a full compaction,  could  induce a noticeable pause. Generational GC tries to make such pauses rarer . In GC pause all threads of your application will be suspended