2. INTRODUCTION
The Java Garbage Collector releases Java objects from memory as
long as no other object refers to that 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 automatically create 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.
It also helps with reduction in memory consumption. .
3. INTRODUCTION
Eclipse MAT quickly analyzes:
Productive heap dumps with hundreds of millions of objects
Quickly calculates the retained sizes of objects,
Checks who is preventing the Garbage Collector from collecting
objects
Runs a report to automatically extract leak suspects.
To tell the JVM to create a heapdump in case of an
OutOfMemoryError use the option:
-XX:+HeapDumpOnOutOfMemoryError
4. INSTALLATION
Install Eclipse MAT via the Eclipse Update manager.
Select "General Purpose Tools " and install:
"Memory Analyser (Incubation)"
"Memory Analyser (Charts)"
5. HOW TO USE ECLIPSE-MAT
Create the Java project “com.fedex.test.first" and the package " com.fedex.test.first “
and Create the following class:
Package com.fedex.test.first;
import java.util.ArrayList;
import java.util.List;
public class Main
{
public static void main(String[] args)
{
List<String> list = new ArrayList<String>(); while (1<2)
{
list.add("OutOfMemoryError test");
} } }
6. RUN PROJECT
In Eclipse add the -XX:+HeapDumpOnOutOfMemoryError to
the runtime configuration and run the project.
7. USING ECLIPSE-MAT
You should get a new file in your project (.hprof).
You may need to refresh your project (F5 on the project) if you are
unable to see the file.
Double-click it and select
"Leak Suspects Report".
8. ANALYSIS
Switch back to the overview and start your investigation of the heap
dump. The user interface is quite intuitive. Especially the dominator
tree gives a quick overview of the objects being used.
You can also create a HeapDump via the jconsole. You can try that by
typing jconsole in the command line to start it.