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.
- 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
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
Article Updates
- 2018-05-13: Link to forensic analysis article added.
Tags: analyzer, dump, eclipse, heap, hprof, Java, jmap, jps, jvm, memory, virtual machine
Details Group Tabs
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,
Date | Ranking | Installs | Clickthroughs |
---|---|---|---|
August 2021 | 39/719 | 523 (0.44%) | 3 |
July 2021 | 40/826 | 1763 (0.44%) | 23 |
June 2021 | 41/842 | 1830 (0.41%) | 16 |
May 2021 | 44/866 | 1684 (0.37%) | 25 |
April 2021 | 44/914 | 1893 (0.4%) | 17 |
March 2021 | 44/918 | 2032 (0.39%) | 14 |
February 2021 | 44/911 | 1567 (0.37%) | 19 |
January 2021 | 45/930 | 1674 (0.37%) | 27 |
December 2020 | 42/919 | 1870 (0.44%) | 19 |
November 2020 | 44/925 | 1925 (0.42%) | 31 |
October 2020 | 42/927 | 2053 (0.44%) | 19 |
September 2020 | 39/894 | 2238 (0.5%) | 15 |
Unsuccessful Installs in the last 7 Days: 1
Count | Error Message |
---|---|
1 | Cannot complete the install because one or more required items could not be found.... |