What's the difference between heap and non-heap memory in the JVM?
⚡
Quick Answer
Heap holds objects and is garbage-collected; non-heap includes metaspace (class metadata), thread stacks, and code cache.
Detailed Answer
Xms/Xmx bound the heap where your objects live and GC runs. Metaspace (post-Java 8, replacing PermGen) grows with loaded classes and lives in native memory. Container OOM-kills often come from non-heap growth the heap flags don't cover — size the whole process, not just -Xmx.
💡
Interview Tip
Container OOMs are often non-heap — mention MaxRAMPercentage.
jvmheapmetaspace