Sunday, March 31, 2013

How to enable MAT (Eclipse Memory Analyzer) in your Eclipse?

When talk about out of memory crashing issue in my Java app, I really felt helpless in finding the root cause. Even though MAT can be an alternative in helping me getting closer to the issue, but in the end of the day, all still depending on the code review and the best practice during the development.

Below are steps to setup the MAT.

1. To install MAT, open Eclipse, click on Help -> Install New Software ->
2. Enter "Add" button and enter "Name" and "Location" into the dialog box
Name: MAT
3. Check the "Memory Analyzer for Eclipse IDE" and "Standalone Memory Analyzer" and click on "Next" button. Follow the step as shown in the wizard, the MAT will be installed into the Eclipse once the Eclipse is restarted.

4. To allow the application to generate hprof file, right click on the project, Run As -> Run Configurations, select "Arguments" tab and enter "-XX:+HeapDumpOnOutOfMemoryError" into "VM arguments" text box.

5. When the Java/Android app crashes, hrof will be generated.

6. Double click on the hprof file, MAT will be launched and select "Leak Suspect Report" option and click on "Finish" button.

7. Leaks Suspect report will be generated.

If you encounter "Parsing heap dump" while opening the hprof file, open the eclipse.ini file which is located at Eclipse home folder. Increase the -Xms and -Xmx size (until the message disappear), refer to the highlighted paragraph as shown below:-


To produce Android hprof file for MAT analysis, launch the DDMS, select device follow by running application. Click on dump HPROF file, the MAT analyzer will be launched.

No comments: