Java - Memory Model & GC

Memory Model & Garbage Collection

Java Memory Model (JMM)

  • Happens-before: ordering and visibility guarantees.
  • Synchronization establishes happens-before relationships.
  • volatile: visibility, not atomicity.

Garbage Collection

  • Generational hypothesis: most objects die young.
  • Common collectors: G1 (default), ZGC (low-latency), Shenandoah (low-pause).
Architect note: Tune GC only when profiling indicates memory/latency pressure; start with defaults for LTS JDKs.