Let's get started with a Microservice Architecture with Spring Cloud:
Tool to Analyze Offline Java Heap Dumps
Last updated: January 28, 2026
1. Overview
It is crucial to analyze the memory consumption to improve the Java application performance and avoid memory problems. Since Java application allocates objects in the JVM heap, monitoring the heap memory and analyzing the objects hosted is very important.
In this tutorial, we’ll introduce two different memory analyzers to demonstrate how we analyze the Java heap memory via an offline heap dump file.
2. Capture Heap Dump
A heap dump is a snapshot of all objects contained in the heap at a specific time point. We could create a heap dump file using certain tools such as VisualVM.
VisualVM is a free profiling tool for Java which bundled with JDK up to version 8. It’s distributed as a standalone application after JDK 8.
We need a program that allows VisualVM to capture the heap dump. Let’s create a sample program to leak memory deliberately:
public class MemoryLeakDemo {
private static final List<InputStream> leakList = new ArrayList<>();
public static void main(String[] args) throws InterruptedException {
int counter = 0;
while (true) {
byte[] chunk = new byte[1024 * 1024];
ByteArrayInputStream bais = new ByteArrayInputStream(chunk);
leakList.add(bais);
counter++;
System.out.println("Allocated " + counter + " MB");
Thread.sleep(100);
}
}
}
This program contains a static variable leakyList. This means it would never be garbage collected. The main method has a loop where it continuously puts 1MB of memory into this static list, which will cause a memory leak.
We are ready to go, and we can run VisualVM to profile it. Once we launch VisualVM, we can see a list of Java processes that are running on the left-hand side “Applications” tab:
Now, we can run the sample program with that, and we’ll see the corresponding Java process show up. Select the process and switch to the “Monitor” tab on the right panel. We would see the chart of heap memory consumption. Go ahead and click the “Heap Dump” button to generate the heap dump snapshot.
We can export that snapshot as a .hprof file for offline analysis. A .hprof file is in binary format that requires an analyzer to read.
3. Analyzing the Heap Dump with VisualVM
VisualVM has the capability of exporting the heap dump file for offline analysis as well.
When we open up the heap dump file, VisualVM presents a summary of the heap dump that contains general information such as the JVM version and a listing of the environment variables (under “System Properties”):
The most informative parts are the “Classes by Number of Instances” and “Classes by Size of Instances”. The first one shows the top 5 classes with the most instances created, while the second one shows the top 5 classes consuming the most heap memory.
If we switch our view from “Summary” to “Objects”, we can get the objects residing in the heap memory. We’ll see the origin of the object creation. In the example below, we can see that the byte array was created in the MemoryLeakDemo:
4. Analyzing the Heap Dump with Eclipse Memory Analyzer Tool (MAT)
Even though VisualVM can perform basic heap inspection, Eclipse MAT is capable of generating more comprehensive reports on memory analysis.
Once we have imported the heap dump file into Eclipse MAT, we can read multiple reports via the “Overview” tab, such as “Top Consumers” and “Top Components”:
The most helpful one for detecting memory leaks is the leak suspects report. It generates an analysis report for us that finds out all potential memory leaks in the heap dump: 
By reading the report details, we can trace where the objects were created, similar to what we saw in VisualVM:
In addition to these comprehensive reports, Eclipse MAT supports Object Query Language (OQL), which is a SQL-like language to query against the heap dump.
Let’s issue a sample query to select all the byte arrays that are over a size of at least 1MB:
SELECT *
FROM byte[] obj
WHERE (obj.@length >= 1048576)
The query result shows there are 715 byte arrays, each with at least 1MB in size. This count aligns with the leak suspects report findings:
6. Conclusion
Memory analysis is the key to optimizing Java application performance. In this article, we have explored how to capture the heap dump and export it as an offline file.
We also looked into various memory analyzers, such as VisualVM and Eclipse MAT, to identify memory leaks.

















