MediumπŸ‘€ 3-5 yearsπŸ‘€ 8-15 years 1 min read

What are the different OutOfMemoryError types, and what does each tell you?

Reviewed by Gurusankar M.

Asked inAmazonMicrosoftDeloitteWipro
#outofmemoryerror#heap space#gc overhead#metaspace#direct buffer
Report issue

⚑ Short Answer

'Java heap space' = heap full (leak or under-sized). 'GC overhead limit exceeded' = GC runs constantly reclaiming little. 'Metaspace' = class/classloader growth. 'Direct buffer memory' = off-heap NIO/Netty. 'unable to create native thread' = too many threads / OS limit. Each points to a different area.

β˜•Coffee Chat Question

Concept Made Simple

β€œWhat are the different OutOfMemoryError types, and what does each tell you?”

🧠Mind Map Answer

Remember It Faster

Java heap space→heap leak / too small
GC overhead limit→thrashing GC, little freed
Metaspace→class/classloader leak
Direct buffer memory→off-heap (NIO/Netty)
unable to create native thread→thread/OS limit

πŸ”₯What If?

Think Beyond the Expected

You hit 'unable to create native thread' but heap is healthy β€” what's wrong?

It's not heap β€” you've exhausted OS threads or native memory for thread stacks (e.g. a thread leak, or ulimit/-Xss too high Γ— many threads). Fix the thread leak / use a bounded pool, or raise the OS thread limit.

πŸ˜‚Real World

The exact OOM message is a free diagnosis β€” it names the exhausted resource. Reading it correctly saves hours vs blindly bumping -Xmx (which only helps 'Java heap space').

🎯Interviewer's Expectation

Keywords they're listening for:

βœ“ distinct OOM messagesβœ“ heap vs metaspace vs off-heap vs threadsβœ“ GC overhead meaningβœ“ message-driven diagnosis

⚠️Common Mistakes

  • βœ—Always bumping -Xmx regardless of OOM type
  • βœ—Ignoring off-heap/native OOMs
  • βœ—Not enabling HeapDumpOnOutOfMemoryError

βœ…Best Practices

  • βœ“Read the OOM message to locate the area
  • βœ“Enable -XX:+HeapDumpOnOutOfMemoryError
  • βœ“Bound threads and off-heap buffers

πŸ”Follow-up Questions

  • 1Why is 'GC overhead limit exceeded' often a precursor to heap OOM?
  • 2How do you cap and monitor direct (off-heap) memory?
  • 3What causes 'unable to create native thread'?

🧩Related Technologies

HeapDumpOnOutOfMemoryErrorNMTNettyMAT

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: Troubleshooting (JVM)
Interview question: "What are the different OutOfMemoryError types, and what does each tell you?"

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?

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.

Related Questions