JVM-ul gestionează automat memoria — alocând obiecte și liberând pe cele inaccesibile prin garbage collection (GC) — deci nu trebuie să liberezi manual memoria. Înțelegerea regiunilor de memorie și comportamentului GC este esențială pentru optimizarea performanței și diagnosticarea problemelor de memorie.
Regiunile de memorie 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+)
