Heap Dump Analysis with Eclipse MAT — Dominator Tree and Leak Suspects
Fast recall
Quick revision
Core answer
jmap -dump:live,format=b,file=heap.hprof , with jcmd GC.heap_dump , or automatically via -XX:+HeapDumpOnOutOfMemoryError. Open the .hprof file in Eclipse MAT and run Leak Suspects — an automated report that identifies the top retainers and likely leak causes. Use the Dominator Tree to rank objects by retained heap (the memory that would be freed if the object were collected). Use Path to GC Roots → exclude phantom/weak/soft references to discover why a suspicious object cannot be collected. The combination almost always points directly at the offending static field, classloader, or unbounded collection.Whether you can actually analyze a heap dump under pressure — not just describe what MAT does
Confusing **shallow heap** (size of the object itself) with **retained heap** (memory that would be freed if the object were collected) — only retained heap reveals the real culprit
Explain the dominator tree algorithm conceptually and demonstrate how to use OQL (Object Query Language) for advanced filtering on million-object dumps
Interview-ready guide
Interview answer
Heap dump analysis with Eclipse MAT is the workhorse technique for diagnosing Java memory issues in production. The workflow is repeatable: capture a snapshot, open it in MAT, run the automated report, drill into the dominator tree, and trace the reference chain to the root cause.
Capturing the dump:
- Always enable
-XX:+HeapDumpOnOutOfMemoryErrorin production — when OOM strikes, the snapshot is already on disk - On-demand with
jcmd— modern replacement forGC.heap_dump /path/to/heap.hprof jmap - For containers — mount a persistent volume so dumps survive restarts
Eclipse MAT workflow:
- Leak Suspects report — automated heuristic analysis; often identifies the root cause in seconds
- Dominator Tree — ranks objects by retained heap, which is the memory that would actually be freed if the object were collected
- Path to GC Roots with weak/soft excluded — reveals the chain of strong references holding the object alive
The shallow vs retained distinction:
- Shallow heap is just the object's own bytes — usually meaningless
- Retained heap is everything reachable only through this object — this is what reveals the real culprit
- A 48-byte HashMap can retain 800MB of data
Advanced — OQL queries:
- SQL-like syntax for filtering:
SELECT * FROM java.util.HashMap WHERE size > 1000 - Useful when the dominator tree alone doesn't pinpoint the issue
Heap dumps complement, not replace, other tools:
- For allocation hot paths — use JFR or async-profiler
- For GC behavior over time — use GC logs and GCEasy
- For thread contention — use thread dumps with
jstack
In an interview, I'd emphasize the discipline: capture, analyze, fix, then capture again to verify the leak is bounded. Many fixes resolve only one of multiple leaks.
Heap Dump Analysis with Eclipse MAT — Dominator Tree and Leak Suspects
Direct Answer
Capture a heap dump with jmap -dump:live,format=b,file=heap.hprof <pid>, with jcmd <pid> GC.heap_dump <path>, or automatically via -XX:+HeapDumpOnOutOfMemoryError. Open the .hprof file in Eclipse MAT and run Leak Suspects — an automated report that identifies the top retainers and likely leak causes. Use the Dominator Tree to rank objects by retained heap (the memory that would be freed if the object were collected). Use Path to GC Roots → exclude phantom/weak/soft references to discover why a suspicious object cannot be collected. The combination almost always points directly at the offending static field, classloader, or unbounded collection.
Common Mistakes & Pitfalls
Confusing shallow heap (size of the object itself) with retained heap (memory that would be freed if the object were collected) — only retained heap reveals the real culprit
Check your understanding
Answer these without looking back at the article.
- What is the difference between shallow heap and retained heap, and why does it matter?
- How do you analyze a heap dump that's larger than the available memory on your laptop?
- What is OQL and when would you use it instead of the standard MAT views?
- How would you correlate a heap dump with allocation profiling data from JFR?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.