The Eclipse Memory Analyzer has been shipped with Eclipse 3.5 Galileo and I planned to start a new series here about memory usage antipatterns and how to analyze them with MAT.
Unfortunately I'm pretty busy these days and I will need more time for those posts.
But, due to popular demand I decided it would make sense to post some good links (ok, I admit some of them are from myself) about how to use the Eclipse Memory Analyzer.
Please forgive me if I missed some important ones, but I'm really hungry now and therefore just stopped after 10 tips ;)
Just read my memory related blogs: Oh that was number 11, but who cares? ;)
Unfortunately I'm pretty busy these days and I will need more time for those posts.
But, due to popular demand I decided it would make sense to post some good links (ok, I admit some of them are from myself) about how to use the Eclipse Memory Analyzer.
Please forgive me if I missed some important ones, but I'm really hungry now and therefore just stopped after 10 tips ;)
- How to really measure memory usage: The absolute fundamentals
- Check the online help. It has a pretty good introduction chapter.
- Memory leaks are easy to find: Learn how to analyze memory leaks
- Check also one click leak analysis if this is your problem :]
- Memory usage analysis: Learn the fundamental approach for finding the owner of a set of objects
- A typical issue in Goggles Android UI framework: Learn how to analyze memory usage on Googles android platform. Shows a typical issue that can be solved by using lazy initialization.
- Never forget to take a look at your Strings: Learn why String.intern() can be useful
- A tip for analysis Equinox based applications: Learn about a special feature for Eclipse based applications.
- Analysing perm size/classloader problems: Perm size problems can be nasty. Check why a Jruby core developer likes MAT ;)
- If you like webinar's here's an introduction presented by the developers.
Just read my memory related blogs: Oh that was number 11, but who cares? ;)

7 Kommentare:
#6 seems to link to #5 in your list
Thanks for the hint!
Fixed!
Great article, Markus.
Thanks!
Hello Markus,
I would like to share my own experience of using MAT.
MAT is really a great tool, but your should known well how to use it! Unfortunately, by default MAT shows some useless windows, so you may be disappointed.
OK, below is my "How to", it would be great to compose a tutorial based on it and include it into MAT docs:
===============================================
How to use Eclipse MAT to analyze memory dumps.
===============================================
Initial steps:
- if working with large heap dumps (> 1 Gb), it is recommended to increase Xmx value in eclipse.ini (ex. -Xmx2400m)
- open your dump (File -> Open heap dump), wait until parsing is finished
- for a fast preview, make a summary histogram (button "Create a histogram from an arbitrary set of object" on the toolbar),
sort by retaind heap, look at object types which retain most of memory (usually, String/char[] and byte[])
1. The first way - using dominator tree grouped by packets/classes
1.1 Press button "Open query browser", in the drop-down menu select "Java Basics -> Open in dominator tree",
type a filter for your classes in "objects" field, ex. "com.yourcompany.yourproject.*",
in the "groupby" field, select "by package", look at the results (retained heap), expand your packets and subpackets,
see how much memory is retained by each packet/subpacket.
This way you may understand which module(s) of your system consume most of memory.
1.2 Select a packet (or a class) you want to investigate (which retains much memory),
in the drop-down menu select "Show retained set",
look at object types which consume most of memory (in the context of the selected package),
you should sort the results by retained heap.
So, you see which types of objects are consumed by some of your modules/subsystems.
1.3 Click on some object type (usually, you look at char[] and byte[]),
in the context menu select "List objects -> with incoming references", sort the results by retained heap.
This way, you will see largest objects of the selected type. You may see their contents, copy them into clipboard
or a file ("Copy" in the context menu)
To see more objects, click on the "Total" line (in the bottom) and select "Next" in the context menu.
1.4 Select an object instance from the result, look at its contents, and also expand incoming references,
analyze why this object is referenced and why this value is here (this depends on your business logic).
It makes sense to look at more objects from the result and analyze them.
1.5 Repeat steps for different object types and also different packets and/or classes
(you are interested in objects which retain most of heap).
2. Another way
2.1 On the summary histogram (see Initial Steps above) select a type (class) which retains much memory (ususally char[]/String, byte[])
2.2 In the context menu select "Show object by class -> by incoming references"
2.3 Expand the resulting tree, look - which class references to it, then look which class references to that class, etc.
2.4 At each step you may look at the retained set of any class ("Show retained set" in the context menu)
or at the concrete object instances ("List objects -> with incoming references" in the context menu).
Hi "Vatel",
Wow, great comment!
I agree that some kind of tutorial would be very helpful. Most of the tips you described are documented somewhere, but there's no tutorial that guides through the most common steps AFAIK. Would you mind if I post this on the MAT dev list?
You can also doit by yourself. We are currently looking for feedback regarding the next steps for MAT.
Regards,
Markus
Thanks, Marcus,
I have posted the HOWTO to mat-dev mailing list,
also I wrote there some comments about how to improve MAT ;)
Post a Comment