Java Zero to All All questionsPractise free
Interview questions › Interview Rapid-Fire — Top Q&A › JVM Internals — Top Interview Q&A

What is Metaspace and how is it different from PermGen?

Level III · MidJVM Internals — Top Interview Q&A
Short answer

Metaspace stores class metadata — class structures, method bytecode, constant pool.

Explanation

PermGen (the permanent generation) served this role until it was removed in Java 8 and replaced by Metaspace. The key difference: PermGen lived inside the heap with a fixed max size (-XX:MaxPermSize), so class-heavy apps hit OutOfMemoryError: PermGen space; Metaspace lives in native (off-heap) memory and grows dynamically by default. You can still cap it with -XX:MaxMetaspaceSize, and leaks (e.g. classloader leaks) surface as OutOfMemoryError: Metaspace.

Common mistakes
  • Saying Metaspace cannot run out.
  • Not knowing class-loader leaks fill it.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for JVM Internals — Top Interview Q&A.

Practise free

More on JVM Internals — Top Interview Q&A