What replaced PermGen with Metaspace, and how can you still get a Metaspace OOM?
Reviewed by Gurusankar M.
β‘ Short Answer
Java 8 replaced fixed-size PermGen with Metaspace, which lives in native memory and auto-grows by default. You still OOM if classes/classloaders leak (e.g. repeated redeploys, dynamic proxy/bytecode generation) or if you cap it with -XX:MaxMetaspaceSize.
βCoffee Chat Question
Concept Made Simple
βWhat replaced PermGen with Metaspace, and how can you still get a Metaspace OOM?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
Metaspace usage climbs every hot redeploy until OOM β root cause?
A classloader leak: old web-app classes can't be unloaded because something pins their ClassLoader, so each redeploy adds another full set of class metadata to Metaspace. Fix the pin (ThreadLocals, drivers, threads); restart instead of hot-redeploy in prod.
πReal World
Frameworks that generate classes at runtime (CGLIB proxies, dynamic languages, lots of lambdas/anonymous classes) and repeated redeploys are the usual Metaspace-growth culprits.
π―Interviewer's Expectation
Keywords they're listening for:
β οΈCommon Mistakes
- βAssuming Metaspace can never OOM
- βNot monitoring Metaspace separately from heap
- βHot-redeploying repeatedly in production
β Best Practices
- βMonitor Metaspace; alert on per-redeploy growth
- βPrefer full restarts over hot redeploys in prod
- βCap MaxMetaspaceSize to fail fast on leaks (carefully)
πFollow-up Questions
- 1How does this relate to a ClassLoader leak?
- 2Should you cap MaxMetaspaceSize in production?
- 3How do dynamic proxies inflate Metaspace?
π§©Related Technologies
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Memory Areas (JVM) Interview question: "What replaced PermGen with Metaspace, and how can you still get a Metaspace OOM?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.