Modern Garbage Collectors in Java
1. G1 Garbage Collector (Garbage-First)
• Introduced in Java 7 (experimental), default in Java 9+
• Designed for low-pause, large heaps, predictable pause times
• Divides heap into many equal-sized regions instead of fixed Young/Old Gen areas
• Collects the regions with the most garbage first (“garbage first”)
• Supports both parallel and concurrent phases
Key features:
• Mixed GC phases: collects both young and old regions in one GC cycle
• Concurrent marking to reduce pause times
• Predictable pause time goals (-XX:MaxGCPauseMillis)
2. Z Garbage Collector (ZGC)
• Introduced in Java 11 (production-ready in Java 15+)
• A low-latency, scalable, concurrent GC designed for heaps from a few GBs to
multi-terabytes
• Targets pause times <10ms, independent of heap size
• Works mostly concurrently with the application
• Uses colored pointers and load barriers to track references without stopping the
world
Key features:
• Concurrent marking, relocation, and cleanup phases
• Region-based heap layout
• Supports heap sizes up to several terabytes
3. Shenandoah GC
• Developed by Red Hat, integrated into OpenJDK in Java 12+
• Similar goals as ZGC: low-pause concurrent GC
• Uses concurrent compaction to avoid long pauses
• Reduces pause times by performing evacuation (relocation of live objects)
concurrently with application threads
4. Epsilon GC (No-Op GC)
• Introduced in Java 11
• A no-op GC that allocates memory but never collects it
• Useful for performance testing and benchmarking, or workloads where you want to
manage memory yourself or expect the process to restart before GC
🆚 Classic vs New GC Summary
Pause Concurre Default in JVM
Collector Target Use Case Heap Size
Times nt? Version
Small heaps, single-
Serial GC Long Small No Java 8+ (option)
core
Parallel Medium- Java 8 default Young
Throughput focus Moderate No
GC large GC
Medium-
CMS GC Low pause old gen Shorter Yes Deprecated since 14
large
Short Medium-
G1 GC Low pause, large heaps Mostly yes Java 9+ default
(~100ms) large
Ultra-low pause, huge
ZGC <10ms Huge (TBs) Yes Java 15+
heaps
Shenand Low pause concurrent Large
<10ms Yes Java 12+
oah GC heaps
Epsilon
Testing (no collection) None N/A No Java 11+
GC