Using jmap and Eclipse Memory Analyzer (MAT) to Diagnose Java OutOfMemoryError
This article explains how to generate a heap dump with jmap, import it into Eclipse Memory Analyzer (MAT), and interpret the various reports such as Histogram, Dominator Tree, Top Consumers, and Leak Suspects to identify memory leaks or insufficient heap sizing in Java applications.
When a Java application suffers from an OutOfMemoryError, the root cause must be identified; after learning to use the jmap command in a previous article, this guide shows how to analyze the resulting heap dump with Eclipse Memory Analyzer (MAT).
MAT is not a universal tool but can parse common heap dump formats like Sun/HP/SAP HPROF and IBM PHD; see the official documentation for details.
OutOfMemoryError typically arises from two scenarios: (1) memory leaks where dead objects are not reclaimed, and (2) memory overflow where live objects exceed the allocated heap, often due to improper -Xmx / -Xms settings or long-lived object references.
Generating Heap Information with jmap
jmap -dump:live,format=b,file=E:/jmap/heap.dump pidThe command creates a binary heap dump file (e.g., heap.dump) in the specified directory.
Importing the Dump into MAT
Open MAT and load the generated .dump file to start analysis.
Generating Analysis Reports
MAT can produce several reports, including Histogram, Dominator Tree, Top Consumers, and Leak Suspects, each visualized with charts and detailed object information.
Histogram
Lists classes, object counts, shallow heap size, and retained heap size, helping to identify which objects occupy the most memory.
Dominator Tree
Shows which threads and their associated objects dominate memory usage.
Top Consumers
Displays the largest memory‑consuming objects and their distribution.
Leak Suspects
Automatically highlights potential leak sources; in the example, a dark region accounts for 62% of a 79.7 MB heap, indicating suspicious code.
By navigating to List Objects → with outgoing references , you can inspect the reference chain of the suspected class.
Further analysis can involve viewing Path To GC Roots (excluding weak references) to trace why objects remain reachable.
The classloader/component "org.apache.catalina.loader.WebappClassLoader @ 0xa34cde8" occupies 19,052,864 (22.80%) bytes. The memory is accumulated in one instance of "java.util.HashMap$Entry[]" loaded by "<system class loader>".This indicates that the Tomcat WebappClassLoader and a large HashMap are major memory consumers, which is normal unless custom classes dominate the heap.
MAT also provides views such as Shortest Paths To the Accumulation Point and Accumulated Objects by Class , revealing that java.util.HashMap instances are heavily retained.
Overall, the tool helps you understand heap composition, locate leaks, and guide code or architecture optimizations.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Big Data Technology & Architecture
Wang Zhiwu, a big data expert, dedicated to sharing big data technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
