RSS

Search Engine

Showing posts with label Eclipse Memory Analyser (MAT) - Tutorial. Show all posts
Showing posts with label Eclipse Memory Analyser (MAT) - Tutorial. Show all posts

Sunday, September 26, 2010

Eclipse Memory Analyser (MAT)

The Java Garbege Collector releases Java objects from memory as long as no other object refers to this object.

A Java heap dump is an image of the complete Java object graph at a certain point in time. It includes all objects, Fields, Primitive types and object references.

It is possible to instruct the JVM to create automatically a heap dump in case of a OutOfMemoryError.

The Eclipse MAT helps to visualize based on Java heap dumps the references to objects and provides tools to identify potential memory leaks.

To tell the JVM to create a heapdump in case of an OutOfMemoryError use the option -XX:+HeapDumpOnOutOfMemoryError

Installation

Install Eclipse MAT via the eclipse update manager . Select "General Purpose Tools " and install "Memory Analyser (Incubation)" and "Memory Analyser (Charts)".

Example

3.1. Create Project

Create the Java project "sawan.modi.mat.first" and the package "sawan.modi.mat.first". Create the following class.

   
package sawan.modi.mat.first;

import java.util.ArrayList;
import java.util.List;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
List list = new ArrayList();
while (1<2){>

3.2. Run Project

In Eclipse add the -XX:+HeapDumpOnOutOfMemoryError to the runtime configuration.

Run the project.

3.3. Use MAT

You should get a new file in your project (.hprof). You may need to refresh your project (F5 on the project). Double-click it and select "Leak Suspects Report".

Switch back to the overview and start your analyses of the heap dump. I believe the user interface is quite intuitive. Expecially the dominator tree gives quickly an overview of the used objects.

Thank you

Thank you for practicing with this tutorial.

I maintain this tutorial in my private time.