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:

  1. Overview: total heap size and the chart of the biggest objects. If one object holds 60% of the heap, the job is almost done.
  2. Leak Suspects: MAT points out suspicious spots on its own. It often gets it right, but I don't trust it blindly.
  3. Dominator Tree: sorted by retained size. For example, a ConcurrentHashMap holds 1.8 GB.
  4. 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 static field ReportCache.INSTANCE.
  5. Histogram: object count by class. If there are 4 million OrderDto instances, 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.