From Passion to Profession
  • Home
  • Notes
  • Projects
  • Resources
    • Discovery Log
    • Books I Read
    • Blogs I Visit
    • Tools I Use
  • Home
  • Notes
  • Projects
  • Resources
    • Discovery Log
    • Books I Read
    • Blogs I Visit
    • Tools I Use

Analyze Heap Dump with Eclipse Memory Analyzer

9/9/2013

0 Comments

 
Ever suspect your Java app leaking memory but not sure which class it is potentially causing OOM? 

In this post, I recommend Eclipse Memory Analyzer (MAT) for developers to analyze heap dumps so you can chase down leak suspects. MAT is much easier to use and read than stand-along jhat unix command, and while monitor memory usage using VisualVM is helpful, MAT gives you specific hints about which classes may be the suspects.

Install Memory Analyzer (MAT) Plugin for Eclipse

Help > Install New Software
Search for ‘memory’
select to install both
Memory Analyzer & Memory Analyzer (Charts)
Install and restart Eclipse

Open Heap Dump

To open a heap dump file (.hprof), have the file be ready (named .hprof) and switch your Eclipse to Memory Analysis perspective:
Make sure your heap dump is named with .hprof extension.
Window > Open Perspective > Other ...
Select Memory Analysis, click OK
then read a heap dump file into Eclipse,
File > Open Heap Dump ...

Increase Eclipse Memory Allocation

Optionally, if you're trying to analyze a bigger .hprof (heap dump) than your Eclipse can handle:
Picture
You need to increase the memory allocation of your Eclipse for running MAT. Since the .hprof is about 10GB in size, I took the following steps to allocate 10GB for my Eclipse on my Macbook Pro:
Highlight Eclipse/GGTS app, right-click, select Show Package Contents
Go to Contents > MacOS
Edit GGTS.ini file
Modify -Xmx768m with -Xmx 10000m
Save
Relaunch Eclipse/GGTS
Repeat Open Heap Dump steps
Open a large .hprof may take a while. In my case, it took about 30 minutes on my Macbook Pro (8GB memory) to open a 10GB .hprof. Eventually, it did come up slowly but surely, whereas my colleague used jhat on a different machine failed to read in the same .hprof after 2 hours of efforts.

Analyse Heap Dump

Right after you successfully open a .hprof heap dump file, the overview tab will show with a pie chart. You can explore by hover over the pie chart, or under the chart, click to run histogram, dominator tree, top consumers, leak suspects, top components, component report. 
Picture
Every time you run a report, a .zip file is likely to be generated along side the .hprof file. The .zip file is the HTML version of the report you can sent to someone and have them view the report using a browser.
Picture
The above retained heap column of Histogram report shows the sum of the shallow heap size of all objects that would be removed when this object is garbage collected. It shows which class is taking up the majority of the memory.
Picture
The key to understanding your retained heap, is looking at the dominator tree above. The dominator tree allows you to identify the largest memory graphs. An Object X is said to dominate an Object Y if every path from the Root to Y must pass through X.

References

  • 10 Tips for using the Eclipse Memory Analyzer
0 Comments



Leave a Reply.

    Categories

    All
    Algorithm
    Concurrency
    CQ
    Data Structure
    Design Pattern
    Developer Tool
    Dynamic Programming
    Entrepreneur
    Functional Programming
    IDE
    Java
    JMX
    Marketing
    Marklogic
    Memory
    OSGI
    Performance
    Product
    Product Management
    Security
    Services
    Sling
    Social Media Programming
    Software Development

    Feed Widget

    Archives

    May 2020
    March 2020
    April 2018
    March 2018
    February 2018
    December 2017
    March 2017
    November 2016
    June 2016
    May 2016
    April 2016
    October 2015
    September 2015
    August 2015
    September 2014
    July 2014
    June 2014
    May 2014
    March 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013

    RSS Feed

in loving memory of my mother  and my 4th aunt
Photos from net_efekt, schani, visnup, Dan Zen, gadl, bobbigmac, Susana López-Urrutia, jwalsh, Philippe Put, michael pollak, oskay, Creative Tools, Violentz, Kyknoord, mobilyazilar