Your SlideShare is downloading. ×
0
Eclipse Memory Analyzer          Tool      Lakshman Kakkirala         little eye labs
Agenda●   Memory Analysis●   Some Definitions●   An example leak code●   Demo of MAT and some basic functionality
Prereqs● Android app development● Basic Heap and Garbage CollectionDisqualification● Advanced knowledge of MAT :-)
littleEye appInsightCT Scanner for your app http://www.littleeye.co
Why Memory Analysis?● Identify Leaks● Reduce memory footprint
Typical problems● Holding Context object (an Activity, a View  or a Drawable)  which actually happens to be an Activity● N...
Some definitions●   Shallow Size●   Retained Size●   Dominator●   Dominator Tree●   GCRoots
Example - Object Graph                          E                 B       100                100      100                3...
Example (contd) - Dominator Tree                             E                 B                             F   A        ...
Example - Memory Leakpublic class MainActivity extends Activity {  private static LeakClass leak;    // *NOT A STATIC*    ...
Investigation Tools - LogCat● D/dalvikvm( 9050 ): GC_CONCURRENT  freed 2049K, 65% free 3571K/9991K,  external 4703K/5261K,...
Heapdump● What - Snapshot of all the objects in the process   ○ Fields, References, Primitive Values   ○ Classes, Class Lo...
MAT aka Eclipse Memory AnalyzerTool● Standalone - Download  http://www.eclipse.org/mat● Pros   ○ Visible Primitive Data   ...
DemoCovering● View Dominator Tree● Inspector  ○ look at the field values  ○ browse through entries in a Collection● Class ...
Demo (contd...)●   Immediate Dominators●   Path from GC roots●   Retained Set●   Object Query Language
References● Google IO 2011 - "Memory Management for Android    apps" http://www.google.    com/events/io/2011/sessions/mem...
Backup SlidesApplication Attributes:<application android:largeHeap="true">
Garbage CollectionPre Gingerbread:GC: stop the world gc, >100msGingerbread and beyond:concurrent gc,two pauses - at the be...
Bitmappre-honeycomb:● pixel data was stored in native mem● recycle() or finalize()● invisible to MAThoneycomb and after:● ...
Typical Garbage CollectionsGC_CONCURRENTGC_FOR_MALLOCGC_EXTERNAL_ALLOC (pre-honeycomb)GC_HPROF_DUMP_HEAPGC_EXPLICIT - app ...
Eclipse Memory Analyzer Tool
Upcoming SlideShare
Loading in...5
×

Eclipse Memory Analyzer Tool

6,907

Published on

This presentation is a basic introduction to MAT. Talks about the basic concepts in Heap Analysis.

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,907
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
118
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Eclipse Memory Analyzer Tool"

  1. 1. Eclipse Memory Analyzer Tool Lakshman Kakkirala little eye labs
  2. 2. Agenda● Memory Analysis● Some Definitions● An example leak code● Demo of MAT and some basic functionality
  3. 3. Prereqs● Android app development● Basic Heap and Garbage CollectionDisqualification● Advanced knowledge of MAT :-)
  4. 4. littleEye appInsightCT Scanner for your app http://www.littleeye.co
  5. 5. Why Memory Analysis?● Identify Leaks● Reduce memory footprint
  6. 6. Typical problems● Holding Context object (an Activity, a View or a Drawable) which actually happens to be an Activity● Non-static inner classes● Caches● Aggressive Caching
  7. 7. Some definitions● Shallow Size● Retained Size● Dominator● Dominator Tree● GCRoots
  8. 8. Example - Object Graph E B 100 100 100 300 A F 100 100 C 100 600 100 200 D 100 100
  9. 9. Example (contd) - Dominator Tree E B F A C D
  10. 10. Example - Memory Leakpublic class MainActivity extends Activity { private static LeakClass leak; // *NOT A STATIC* class LeakClass { } @Override public void onCreate(Bundle savedInstanceState) { .... if (leak == null) { leak = new LeakClass(); } ... }}
  11. 11. Investigation Tools - LogCat● D/dalvikvm( 9050 ): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms
  12. 12. Heapdump● What - Snapshot of all the objects in the process ○ Fields, References, Primitive Values ○ Classes, Class Loaders● How to generate ○ DDMS view - "Dump HPROF file" icon ○ android.os.Debug.dumpHprofData(<filename>) ○ signal 10● Convert to standard HPROF format ○ hprof-convert (only required if using standalone)
  13. 13. MAT aka Eclipse Memory AnalyzerTool● Standalone - Download http://www.eclipse.org/mat● Pros ○ Visible Primitive Data ○ Powerful selection model ○ No setup● Cons ○ Large dump files ○ Cannot answer code/temporal questions ■ Who/Where/When - an object is created ■ When - an object is garbage collected
  14. 14. DemoCovering● View Dominator Tree● Inspector ○ look at the field values ○ browse through entries in a Collection● Class Histograms● Group by Value
  15. 15. Demo (contd...)● Immediate Dominators● Path from GC roots● Retained Set● Object Query Language
  16. 16. References● Google IO 2011 - "Memory Management for Android apps" http://www.google. com/events/io/2011/sessions/memory-management-for- android-apps.html● Java Memory Analysis http://vimeo.com/21356498● Markus Kohlers Java Performance Blog http://kohlerm.blogspot.com● Memory Analyzer Blog http://memoryanalyzer.blogspot.in/
  17. 17. Backup SlidesApplication Attributes:<application android:largeHeap="true">
  18. 18. Garbage CollectionPre Gingerbread:GC: stop the world gc, >100msGingerbread and beyond:concurrent gc,two pauses - at the beginning and at the end < 5mspartial collections
  19. 19. Bitmappre-honeycomb:● pixel data was stored in native mem● recycle() or finalize()● invisible to MAThoneycomb and after:● pixel data inside dalvik heap● visible to MAT● works with partial and concurrent GC
  20. 20. Typical Garbage CollectionsGC_CONCURRENTGC_FOR_MALLOCGC_EXTERNAL_ALLOC (pre-honeycomb)GC_HPROF_DUMP_HEAPGC_EXPLICIT - app calling System.gc()
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×