Why it matters

Every JVM performance problem eventually touches memory. OOMs, long GC pauses, and memory leaks all trace to the memory layout. Knowing where objects live is what makes tuning informed.

Advertisement

The architecture

Heap: the main allocation area, controlled by -Xms and -Xmx. Split into young generation (Eden + two survivor spaces) and old generation. New objects allocate in Eden; survivors of GC move to survivor spaces, then to old.

Stack: per-thread, holds frames with local variables and operands. Fixed size per thread (-Xss).

JVM memory regionsHeapyoung + oldStackper-thread framesMetaspace + off-heapclass metadata + directEach region has its own GC or lifecycle; understand which holds your allocations
Four main memory regions.
Advertisement

How it works end to end

Metaspace: native memory holding class metadata (methods, fields, constants). Grows as classes load; unbounded by default (limit with -XX:MaxMetaspaceSize).

Off-heap: java.nio.ByteBuffer.allocateDirect() creates buffers outside the Java heap. Used by IO libraries for zero-copy. Not managed by GC; must be released via GC.

Generational hypothesis: most objects die young. Young generation is collected frequently and quickly. Survivors promote to old generation, which is collected less often but more expensively.