Eclipse
memory analyzer is a java heap analyzer that helps to find memory leaks and
reduce memory consumption.
Install MAT
Analyzer
We
need to install two eclipse plugins:
1. BIRT Chart Engine: For Getting Memory
Information with Pie Chart diagrams
2. MAT: For Getting Memory Information
1.
Install BIRT Chart Engine plugins
Eclipse —> Help Menu —> Install New
Software —> Add
Enter below information
Name: BIRT Chart Engine.
Location: http://download.eclipse.org/birt/update-site/4.3
Now select only Birt Chart Engine and Go
for Install.
2.
Install MAT plugins
Eclipse —> Help Menu —> Install New
Software —> Add
Enter below information
Name: MAT
Location: http://download.eclipse.org/mat/1.3/update-site/
Generate Dump file
for MAT Analysis
I
had written simple java program, which requires lot of heap to initialize, and
finally results in “OutOfMemoryError”.
public class HeapError { public static void main(String args[]){ HeapError obj[] = new HeapError[100000000]; for(int i=0; i<100000000; i++) obj[i] = new HeapError(); System.out.println("I am done"); } }
We
need to do some setting to generate heap dump for this application.
Step 1: Right click on
program and open “Run configurations”.
Step 2: Go to arguments tab
and add
“-XX:+HeapDumpOnOutOfMemoryError”
as VM argument. And run the application.
Step 3: After running
application, you can see below messages in console.
java.lang.OutOfMemoryError: Java heap space Dumping heap to java_pid912.hprof ... Heap dump file created [3482503 bytes in 0.383 secs] Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at mat_demo.HeapError.main(HeapError.java:5)
Message
in console clearly stating that dump is generated to file “java_pid912.hprof”.
Step 4: Dump file is
located in project folder itself, so refresh the project.
After
refreshing, you can see the dump file.
Double
clik the dump file, it starts MAT wizard and select the option “Leak Suspects
Report” and press Finish.
It
opens system overview report and displays possible problem suspects in pie
chart.
Go
through below link for more details about Eclipse MAT Analyzer.
No comments:
Post a Comment