Walk through the JVM memory model. Where does each piece of data live and what OOMs can you hit?
Production Java bugs are often OOMs or leaks. Interviewers expect you to map symptom → area (heap OOM vs metaspace OOM vs stack overflow).
Name the areas: heap (shared, GC-managed), stack (per-thread, frames), metaspace (class metadata, replaces PermGen in Java 8+), PC register, native stack, direct memory.
Heap is split into young (Eden + two Survivor) and old. Most objects die young — generational hypothesis.
Stack holds local variables and frames. StackOverflowError = too-deep recursion. Each thread has its own stack, default ~1MB on Linux x64.
Metaspace lives in native memory, not heap. "Metaspace OOM" usually means classloader leak (hot reload frameworks, dynamic proxies).
Direct memory is outside heap. NIO ByteBuffers, Netty allocate here. Can OOM even when heap has room.
I think about JVM memory by failure mode. Heap OOM means too many live objects or a leak — take a heap dump, analyze with MAT. Metaspace OOM means classloader leak — usually hot-reload or dynamically generated classes. StackOverflowError means recursion too deep, often accidental infinite recursion. DirectBuffer OOM is native memory, heap has room but the OS refuses more. Each thread gets its own stack (~1MB default), so 10K threads eat 10GB before any heap is touched — that's why reactive frameworks push you off thread-per-request.
MaxMetaspaceSize is unlimited by default — set it to fail fast on classloader leaks.
Thread stack size is -Xss. Reduce if you need many threads; raise if deep recursion.
HireMe AI (即答侠) tracks which JVM OOM type each answer addresses so you never confuse heap and metaspace.
PermGen had a fixed max size that caused frequent OOMs on app redeploys. Metaspace auto-grows in native memory, and is easier for the JVM to size dynamically.
On heap since Java 7. Strings interned via String.intern() live in the heap string pool, collected by GC.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free