Video in progress
You opened a heap dump in Eclipse MAT. How do you find out who is holding the memory?
First I look at the Leak Suspects report, then the Dominator Tree, which sorts objects by retained size. From the biggest object I use "Path to GC Roots" to find who is holding it.
📖 Answer
My usual sequence:
- Overview: total heap size and the chart of the biggest objects. If one object holds 60% of the heap, the job is almost done.
- Leak Suspects: MAT points out suspicious spots on its own. It often gets it right, but I don't trust it blindly.
- Dominator Tree: sorted by retained size. For example, a
ConcurrentHashMapholds 1.8 GB. - Right-click that object, then Path to GC Roots, exclude weak/soft references. This answers "why isn't this being collected": for example, through the
staticfieldReportCache.INSTANCE. - Histogram: object count by class. If there are 4 million
OrderDtoinstances, you need to find where they come from.
Useful extras:
- OQL queries:
SELECT * FROM java.lang.String s WHERE s.value.length > 100000; - comparing two dumps (an hour apart) shows clearly what keeps growing.
A practical tip: opening an 8 GB dump takes a lot of memory for MAT too. Raise -Xmx in MemoryAnalyzer.ini, or pre-index the dump on a big server with ParseHeapDump.sh.
Sign up to mark studied questions and save your progress.