Eclipse Memory Analyzer

The MemoryAnalyzer Plugin for Eclipse allows us to quickly analyze heap dumps from a virtual machine and search for memory leaks. In the following tutorial we’re going to create and run a small application that is going to cause an OutOfMemoryException during its runtime.

In addition, we’re forcing the virtual machine to save a heap dump and finally analyzing this data using Eclipse and the MemoryAnalyzer plugin.

Contents

Abstract: How do you analyze Java OutOfMemoryErrors and perform application and thread heap sizing? This talk covers the open source Eclipse Memory Analyzer.

  1. Taking a Heap Dump from a running Application

Prerequisites

Install the Eclipse Plugin

The good thing is that you don’t need to add any update site in Eclipse .. just search for MemoryAnalyzer and install the plugin..

This tool is based on the Eclipse Memory Analyzer (MAT) project, and uses the IBM® Diagnostic Tool Framework for Java (DTFJ) feature to enable the processing of dump files from IBM virtual machines. Memory Analyzer is provided as an IBM Support Assistant (ISA) add-on. The Eclipse Memory Analyzer™ is a fast and feature-rich Java heap analyzer that helps you find memory leaks and reduce memory consumption. Use the Memory Analyzer to analyze productive heap dumps with hundreds of millions of objects, quickly calculate the retained sizes of objects, see who is preventing the Garbage Collector from collecting objects, run a report to automatically extract leak. The Eclipse Memory Analyzer tool (MAT) is a fast and feature-rich heap dump analyzer that helps you find memory leaks and analyze high memory consumption issues. With Memory Analyzer one can easily. Find the biggest objects, as MAT provides reasonable accumulated size (retained size) explore the object graph, both inbound and outbound. Downloading the Memory Analyzer (MAT) There are two ways to use the Memory Analyzer tool. Integrating MAT plugin with Eclipse. Open Eclipse IDE and select Help Eclipse Marketplace. Search for Memory Analyzer and install it. Restart Eclipse and the plugin is ready to be used. Downloading the standalone version of Eclipse MAT.

Eclipse MemoryAnalyzer Plugin Installation

Creating a Crash

The following code should product an OutOfMemoryException soon (never use Integer.MAX_VALUE in a loop’s stop condition this way – you’ll never reach an end..). To speed this thing up we’re giving the virtual machine a heap size maximum of 10MB using the start parameter -Xmx10M

The following start parameter forces the virtual machine to create a heap dump in a file named /tmp/heap.bin when an OutOfMemoryError occurrs: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heap.bin

Run the app and the following output should appear soon – the app is available from the tutorial sources for download as an executable jar (dummy/outofmemory.jar).

Taking a Heap Dump from a running Application

Of course you’re able to analyze a running application and the following tools bundled with your JDK might help you there:

jps

jps allows you to list running java applications and shows you their process id

Eclipse Memory Analyzer

jmap

Eclipse memory analyzer

jmap allows you to create a dump from a specific java process – as an example, the following code creates a heap dump in binary format in a file /tmp/heap.bin for the running java process with id 2381:

Analyzing Data

Now start your Eclipse and select File > Open .. and select the dump file .. e.g. /tmp/heap.bin from the example above .. the analyzer plugin will start to read the dump automatically..

Loading the heap dump

Having finished loading the dump a nice wizards helps you to create one of the several available reports ..

You’ve got several reports, statistics and interesting pieces of information there so have some fun playing around with the different features :)

Memory Usage Chart

Tutorial Sources

I have put the source from this tutorial on my Bitbucket repository – download it there or check it out using Mercurial:

Eclipse Memory Analyzer Mac

Resources

Forensic Analysis

I have summarized different tools and workflows for analyzing Java applications and systems (including the Eclipse Memory Analyzer) here: http://app.hascode.com/forensic/

Article Updates

  • 2018-05-13: Link to forensic analysis article added.

Tags: analyzer, dump, eclipse, heap, hprof, Java, jmap, jps, jvm, memory, virtual machine

Analyzer

Details Group Tabs

Details

Eclipse Memory Analyzer Mat

The Eclipse Memory Analyzer is a fast and feature-rich Java heap analyzer that helps you find memory leaks and reduce memory consumption. Use the Memory Analyzer to analyze productive heap dumps with hundreds of millions of objects, quickly calculate the retained sizes of objects, see who is preventing the Garbage Collector from collecting objects, run a report to automatically extract leak suspects.

  • mat,
  • memory,
  • heap,
  • analyzer,
  • leaks,
Additional Details
2019-12 (4.14), 2019-09 (4.13), 2019-06 (4.12), 2019-03 (4.11), 2018-12 (4.10), 2018-09 (4.9), Photon (4.8), Oxygen (4.7), Neon (4.6), Mars (4.5), Luna (4.4), Kepler (4.3), 2020-03 (4.15), 2020-06 (4.16), 2020-09 (4.17), 2020-12 (4.18), 2021-03 (4.19)
Metrics
DateRankingInstallsClickthroughs
August 202139/719523 (0.44%)3
July 202140/8261763 (0.44%)23
June 202141/8421830 (0.41%)16
May 202144/8661684 (0.37%)25
April 202144/9141893 (0.4%)17
March 202144/9182032 (0.39%)14
February 202144/9111567 (0.37%)19
January 202145/9301674 (0.37%)27
December 202042/9191870 (0.44%)19
November 202044/9251925 (0.42%)31
October 202042/9272053 (0.44%)19
September 202039/8942238 (0.5%)15
Errors

Unsuccessful Installs in the last 7 Days: 1

CountError Message
1Cannot complete the install because one or more required items could not be found....
Download last 500 errors (CSV)