JVM mengelola memori secara otomatis — mengalokasikan objek dan membebaskan yang tidak dapat dijangkau melalui pengumpulan sampah (GC) — sehingga Anda tidak perlu membebaskan memori secara manual. Memahami wilayah memori dan perilaku GC sangat penting untuk menyetel kinerja dan mendiagnosis masalah memori.
Wilayah memori JVM
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+)
