Java Garbage Collection
2026-11-18 ยท garbage collection
notes / DOCS
Required reading: Java Garbage Collectors
In Java
- serial gc
- parallel gc
- concurrent mark sweep
- garbage first (G1)
- zgc
- shehnandoah gc
- epsilon gc
- azul c4 gc
- ibm metronome gc
- sap garbage collector
1. Serial Garbage Collectors
- single threaded pause execution to clean memory
initial mark: all objects directly referenced
|
v
(serial) marking: traverse reachable objects
|
v
remark: resume briefly and continue marking
|
v
sweep and compact: sweep memory to dealloc 0 refs, compact to contiguous
|
v
free: update free memory
Costs:
- high pause times
- singlethreaded
Pros:
- simplest to implement and use
2. Parallel GC
- momentary pause for initial mark
- concurrent marking
- short pause for final remark
- concurrent sweep/compaction
Costs:
Pros:
- takes advantage of multithreaded
3. CMS
handle object modifications during the concurrent marking
- no compacting: leads to fragmentation which is why you handle allocation differently with your data structures that are handled in concurrent reset
Costs:
- more complex work
- cpu intensive
- no compaction for some reason?
Pros:
- takes advantage of multithreaded but better
- reduced pause times
4. G1 (Garbage-First) GC
- initial mark
- concurrent marking
- final remakr
- cleanup -> largest hole first
- compacts objects into fewer regions to reduce fragmentation
- evacuation: transfer live objects from one region to another (prof says this isn't true??)
Costs:
- cpu intensive
- bad for smaller heaps
Pros:
- Generational
- compaction
- suitable for large heaps
5. ZGC
designed for large heaps
- initial mark
- concurrent marking
- remark
- concurrent relocation: free up fragmented memory
- final marking
- reference processing
Costs:
- cpu intensive (obviously atp)
Pros:
- "ultra low latency systems" idek
- high memory based systems (terabytes apparently)
6. Shehnandoah GC
large heaps and low latency, concurrent evacuation
"G1 on steriods"
- initial mark
- concurrent marking
- concurrent evacuation: reclaims garbage, copies live objects to new regions
- update references
- final mark
- cleanup
Pros:
- can concurrently relocate objects
7. Epsilon GC
special purpose when GC not required (no-op gc) basically a fake gc
not even that its basically no gc at all why tf does it have a name
8. Azul C4 GC
~explosive~
Continuously Concurrent Compacting Collector
- initial mark
- concurrent marking
- remark phase
- concurrent relocation: comacting
- final remark
fucking proprietary
9. IBM metronome gc
metronome trauma
real time systems with strict determinism, low pause times
- initial mark
- concurrent marking
- incrementatl relocation -> repeated incrementally
- references updates
- collection completion: free memory
10. SAP GC
also proprietary welp
- generational collection: based on age of objects
- concurrent collection
- incremental collection
- compaction
