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. Some definitions
● Shallow Size
● Retained Size
● Dominator
● Dominator Tree
● GCRoots
8. Example - Object Graph
E
B 100
100 100
300
A F
100 100
C 100
600
100
200 D
100
100
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. MAT aka Eclipse Memory Analyzer
Tool
● 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. Demo
Covering
● View Dominator Tree
● Inspector
○ look at the field values
○ browse through entries in a Collection
● Class Histograms
● Group by Value
15. Demo (contd...)
● Immediate Dominators
● Path from GC roots
● Retained Set
● Object Query Language
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 Kohler's Java Performance Blog
http://kohlerm.blogspot.com
● Memory Analyzer Blog
http://memoryanalyzer.blogspot.in/
19. Garbage Collection
Pre Gingerbread:
GC: stop the world gc, >100ms
Gingerbread and beyond:
concurrent gc,
two pauses - at the beginning and at the end
< 5ms
partial collections
20. Bitmap
pre-honeycomb:
● pixel data was stored in native mem
● recycle() or finalize()
● invisible to MAT
honeycomb and after:
● pixel data inside dalvik heap
● visible to MAT
● works with partial and concurrent GC