Memory management in Java is handled automatically by the Java Virtual Machine (JVM). At the heart of this system is Garbage Collection (GC)βan automated process designed to track down unreferenced objects in memory, reclaim their allocated space, and prevent memory leaks and OutOfMemoryError failures.
The JVM Heap Memory Architecture To understand how Java reclaims memory, you must first understand how memory is structured within the JVM. Java organizes heap memory based on the Weak Generational Hypothesis, an empirical observation that most objects created during execution die young (e.g., temporary variables, request/response DTOs, iterator instances).
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β JVM HEAP β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ β
β β YOUNG GENERATION β β OLD GENERATION β β
β β β β (TENURED) β β
β β ββββββββββββββββ ββββββββββββββ ββββββββββ β β β β
β β β Eden Space β β Survivor S0β βSurv S1 ββ¦