Mark and sweep

JVM uses the mark and sweep algorithm for garbage collection. Mark and sweep collection consists of two phases.

During the mark phase, all the objects that have live references are marked alive, the rest are presumed candidates for garbage collection. During the sweep phase, the space occupied by the garbage collectable candidates is added to the free list, that is, they are available to be allocated to the new objects.

There are two improvements to mark and sweep. One is concurrent mark and sweep (CMS), and the other is parallel mark and sweep. CMS focuses on lower latency, while the latter focuses on higher throughput. Both strategies have performance trade-offs. CMS does not do compaction, while parallel garbage collector (GC) performs only whole-heap compaction, which results in pause times. As a thumb rule, for real-time streaming, CMS should be used; parallel GC otherwise.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset