Java / Java 17 Garbage Collection Interview Questions
What is Metaspace in Java 17?
Metaspace is the native (off-heap) memory region that stores class metadata - method bytecode, constant pools, field and method descriptors - for every loaded class. It replaced the old PermGen starting in Java 8.
Unlike PermGen, which had a fixed maximum size carved out of the JVM's own memory, Metaspace grows dynamically from native memory as needed, bounded only by -XX:MaxMetaspaceSize (unlimited by default) and available system memory.
Metaspace for a given class is only reclaimed when the ClassLoader that loaded it becomes completely unreachable, which is why long-running applications that repeatedly load classes through short-lived classloaders (hot redeploys, dynamic proxies) are the most common source of Metaspace growth.
More Related questions...