The JVM automatically manages memory — allocating objects and freeing unreachable ones via garbage collection (GC) — so you don't manually free memory. Understanding the memory regions and GC behavior is key to tuning performance and diagnosing memory issues.
JVM memory regions
HEAP — where all OBJECTS live (shared across threads), GC operates here
├── Young Generation — new objects (most die young)
│ ├── Eden — new allocations go here
│ └── Survivor — objects that survived a young GC
└── Old (Tenured) Gen — long-lived objects (promoted from young)
STACK — per-thread; method frames, local variables, primitive locals, references
Metaspace — class metadata (replaced PermGen in Java 8+)
