In this lecture, we explore how the garbage collector (
GC) in the
JVM works, how classic
Serial/
Parallel/
CMS differ from modern
G1,
ZGC, and
Shenandoah, what young and old generations are, why
Stop-the-World pauses happen, and how to minimise them. In practice, we’ll see how to enable different GCs with flags (
-XX:+UseG1GC,
-XX:+UseZGC,
-XX:+UseShenandoahGC), tune pauses (
-XX:MaxGCPauseMillis) and heap sizes (
-Xms/
-Xmx), read logs (
-Xlog:gc*), and avoid common mistakes (for example, forcing a call to
System.gc()).