Java / JVM Architecture (Java21) Interview questions
What is Metaspace, and how does it differ from PermGen?
Metaspace is the HotSpot implementation of the Method Area used since Java 8, storing class metadata such as the runtime constant pool, field/method data, and bytecode.
It replaced PermGen ("Permanent Generation"), which lived inside the fixed-size heap in Java 7 and earlier and was a frequent source of OutOfMemoryError: PermGen space, especially in application servers that repeatedly redeployed apps and accumulated classloader-held classes.
| PermGen (Java ≤7) | Metaspace (Java 8+) |
| Lives inside the heap, fixed max size | Lives in native (off-heap) memory, grows dynamically by default |
Sized with -XX:MaxPermSize | Sized with -XX:MaxMetaspaceSize (unlimited unless set) |
Metaspace still isn't infinite in practice - it competes with the OS for native memory, so an unbounded classloader leak can still exhaust it, just without the old fixed-size ceiling.
More Related questions...