JavaAdvanced#gc#jvm

What is the difference between G1, CMS, and ZGC garbage collectors?

CMS (deprecated) minimizes pause times using concurrent marking but suffers fragmentation. G1 (default since Java 9) divides the heap into regions and balances throughput with predictable pause times. ZGC is a low-latency collector designed for huge heaps with sub-millisecond pause times.

Example
// JVM flags to select a collector:
java -XX:+UseG1GC MyApp
java -XX:+UseZGC MyApp

Related Questions

1
JavaIntermediate#gc#memory

What is the purpose of the finalize() method and why is it discouraged?

Open
2
JavaIntermediate#serialization

What is serialization in Java?

Open
3
JavaIntermediate#serialization

What is the purpose of serialVersionUID?

Open