MediumExperience level: 3-5 years · 8-15 years1 min read

What replaced PermGen with Metaspace, and how can you still get a Metaspace OOM?

Reviewed by Gurusankar M.

Asked inAmazonDeloitteCognizant
#metaspace#permgen#class metadata#oom#classloader
Report issue

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.

On this page

Concept Made Simple

Coffee Chat Question

“What replaced PermGen with Metaspace, and how can you still get a Metaspace OOM?”

Remember It Faster

Mind Map Answer

PermGen (≤7)
fixed size in heap → frequent OOM
Metaspace (8+)
native memory, auto-grows
Still OOMs
classloader/class leak or capped size

Think Beyond the Expected

What If?

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:

  • PermGen fixed/in-heap
  • Metaspace native/auto-grow
  • classloader leak cause
  • dynamic class generation
  • MaxMetaspaceSize cap

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

  1. How does this relate to a ClassLoader leak?
  2. Should you cap MaxMetaspaceSize in production?
  3. How do dynamic proxies inflate Metaspace?

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.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.