How to analyse Heap dumps using Eclipse MAT

We have seen in previous article about how to generate Heap dumps. Once we have heap dump, we need analyse them to find out possible cause of OOME. Let’s see how to analyse Heap dumps using Eclipse MAT

For this we would need a Heap dump. Let’s create a simple program that generates Heap dump

OOME generating Program

The program is simple, we just keep on adding data to an in-memory hashmap. Let’s quickly see the code

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;

public class Oome {

  static Map<Integer, ByteBuffer> dataum;

  public static void fillMemory() {
    dataum = new HashMap<>();
    int i = 0;
    while(true) {
      dataum.put(i++, ByteBuffer.allocate(2048 * 10));

  public static void main(String[] args) {


Next we run it with command line option to generate Heap Dump when it goes out of Memory. Details covered here

Once you run the program, you would see something like this

java.lang.OutOfMemoryError: Java heap space
Dumping heap to /Users/codezuzu/java_pid11912.hprof ...
Heap dump file created [881810609 bytes in 3.670 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at java.nio.HeapByteBuffer.<init>(
	at java.nio.ByteBuffer.allocate(
	at junk.Oome.fillMemory(
	at junk.Oome.main(

Getting Eclipse MAT

You would need Eclipse MAT to be installed on Eclipse. More details here

Analyse Heap dump in Eclipse MAT

Launch Eclipse and open the Window > Open Perspective > Memory Analysis

Click on Open Heap dump

Open Heap dump

Open Heap dump

Eclipse MAT would parse the Heap dump and open a UI shown in image below (UI prompts for selecting an option, choose Leak suspect report)


Once done, the UI shall show possible leak suspects


Here it shows that Hashmap is the causing the OOME. This case is simple, but many times you would need to dig deeper trying to figure out what actually is taking the memory. If we need to dig deeper and try to find out the content of Hashmap, we would use “Open Dominator tree for entire heap” option from the tool bar


This would open a UI with all the heap contents shown as tree


Using the UI, we can browse the heap content and find out what is causing the memory pressure. This shall provide pointers to further course of action like tuning heap settings or optimising Application.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.