What are the different OutOfMemoryError types, and what does each tell you?
Reviewed by Gurusankar M.
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.
On this page
Concept Made Simple
Coffee Chat Question
“What are the different OutOfMemoryError types, and what does each tell you?”
Remember It Faster
Mind Map Answer
- 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
Think Beyond the Expected
What If?
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
- Why is 'GC overhead limit exceeded' often a precursor to heap OOM?
- How do you cap and monitor direct (off-heap) memory?
- What causes 'unable to create native thread'?
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?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair