A JVM gerencia automaticamente a memória — alocando objetos e liberando os inacessíveis via garbage collection (GC) — para que você não libere manualmente a memória. Entender as regiões de memória e o comportamento do GC é fundamental para otimizar o desempenho e diagnosticar problemas de memória.
Regiões de memória 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+)
