Thursday, July 09, 2009

Eclipse Memory Analyzer, 10 useful tips/articles

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 ;)

  1. How to really measure memory usage: The absolute fundamentals
  2. Check the online help. It has a pretty good introduction chapter.
  3. Memory leaks are easy to find: Learn how to analyze memory leaks
  4. Check also one click leak analysis if this is your problem :]
  5. Memory usage analysis: Learn the fundamental approach for finding the owner of a set of objects
  6. 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.
  7. Never forget to take a look at your Strings: Learn why String.intern() can be useful
  8. A tip for analysis Equinox based applications: Learn about a special feature for Eclipse based applications.
  9. Analysing perm size/classloader  problems: Perm size problems can be nasty. Check why a Jruby core developer likes MAT ;)
  10. 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? ;)





36 comments:

  1. #6 seems to link to #5 in your list

    ReplyDelete
  2. 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).

    ReplyDelete
  3. 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

    ReplyDelete
  4. Thanks, Marcus,
    I have posted the HOWTO to mat-dev mailing list,

    also I wrote there some comments about how to improve MAT ;)

    ReplyDelete
  5. thanks, understand lots from your article, by the way, do you know the simple way to measure the android code coverage of java?

    ReplyDelete
  6. Hi,
    I guess you want to use a tool like "emma" to measure code coverage.
    I haven't tried it yet, but http://blog.lv25.com/2009/08/emma-code-coverage-for-your-android.html
    is talking about using emma together with android.
    Regards,
    Markus

    ReplyDelete
  7. But Markus is there any way to look into primitives through this, I tried but didn't succeeded in this?

    Hope you'll help.

    Also please post more interesting articles as yours are really good.

    --Deepak

    ReplyDelete
  8. Just finished reading through the your first 3 posts, as well as Vatel's "guide".

    Very helpful for a beginner to start investigating a large heap!

    Thanks,
    Taylor

    ReplyDelete
  9. Very good post.

    Is there any other data type than String that you recommend using for a big HashMap?
    Currently I'm using a HashMap, but it still uses a lot of heap. The Boolean is not used, only the String to find if another String exists in the HashMap or not. Boolean was the smallest I could think of but it still seems to use 16bytes heap...

    ReplyDelete
  10. My previous post got a bit edited...
    I'm using a HashMap (String,Boolean) where the String is the key and Boolean the value...

    ReplyDelete
  11. This is one of the good post.I like your blog clarity.Nice to read about your post.Supper.

    ReplyDelete
  12. is there any place can find more about the mat with sample example

    ReplyDelete
  13. We should get connected to Memory Improving optimizer, that is specially designed to increase memory efficiency.

    ReplyDelete
  14. The blog and data is excellent and informative as well.lastingimpressionsfoam.com

    ReplyDelete
  15. Your blogs and every other content is so entertaining and useful It makes me come back again.copy contacts from HTC Wildfire to iPhone

    ReplyDelete
  16. Thumbs up guys your doing a really good job.Breastfeeding tops

    ReplyDelete
  17. Thank you very much for sharing informative and useful post. The Eclipse Memory Analyzer (MAT) the tool is useful for both tracking memory leaks and for periodically reviewing the state of your system.

    ReplyDelete
  18. Marvelous work pals, I love reading your articles. payday loan lenders

    ReplyDelete
  19. Your blogs are totally worth giving time and energy.
    bonecancer

    ReplyDelete
  20. I am for sure returning again for more contents of yours.

    Iphone

    ReplyDelete
  21. I’m surely coming again to read these articles and blogs

    youtubedownloadsoftware

    ReplyDelete
  22. I agree that this is a kind of tutorial is very useful. Most of the advice that I have described are documented somewhere, but there is no tutorial that walks you through the steps as I know the most common. Mind if I'll post a list of MAT developer?
    You can even milk. We are currently looking for information on the next steps of the APU.

    ReplyDelete
  23. I really enjoy while I read your blogs and articles.
    itjobs

    ReplyDelete
  24. I’m flattened by your contents keep up the excellent work. Get more info about Barato Website

    ReplyDelete
  25. The abysmal you dig into the content and communicate us the precise aggregation is appreciable.
    bestinsurance

    ReplyDelete
  26. It's never too lately to meliorate your information and your listing has me.
    what is the best investment

    ReplyDelete
  27. Your blogs and information attracts me to come back again n again. android development technology

    ReplyDelete
  28. I’m glad to find so many useful and informative data on your website. Full AM-tek Center Article

    ReplyDelete
  29. No wonder why you get so many feedbacks
    Discover Artist All Opera

    ReplyDelete
  30. I think I have really come on the right place for getting the perfect info.
    Look for W Terg Here

    ReplyDelete