NOTE

Garbage Collection Algorithms

Mark-sweep, copying, compaction, generational collection, and the throughput/latency/space trade-offs behind modern JVM collectors.

JavaCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Mark and Sweep

Tracing first discovers live objects; sweep then reclaims unreachable regions. The simple form may leave fragmentation.

2. Copying / Evacuation

Live objects are copied from one region to another. This can make allocation and compaction efficient when the live fraction is small, at the cost of copy work and reserved destination capacity.

3. Mark-Compact

After identifying live objects, the collector moves/compacts them so free space becomes contiguous. Compaction reduces fragmentation but requires relocation work and reference updates.

4. Generational Collection

The generational hypothesis observes that many objects die young. Collectors can therefore collect young objects frequently and long-lived data less frequently, while remembering cross-generation references.

Not every modern collector exposes exactly the same generation model, and collector designs continue to evolve.

5. The Real Trade-off

There is no universally best algorithm. Designs trade among throughput, pause time, allocation rate, memory overhead, fragmentation, CPU usage, and implementation complexity. Evaluate the collector against the application’s latency SLO and live-set behavior.

Loading helpful count