Memory Management for Android Apps Min Ji, Kim Embedded Software Lab.
2/27 Embedded Software Lab. Introduction Google I/O Development Conference, 2011 Google I/O Development Conference ?? Thousands of developers’ festival for two days of deep technical contents. Android, Google Chrome, Google APIs, Google Web Toolkit, App Engine, etc.
3/27 Embedded Software Lab. No more memory management? 512MB RAM2GB RAM
4/27 Embedded Software Lab. Heap Size Heap size limits(for multi-tasking) Nexus One: 32MB Galaxy S: 48MB Nexus 7: 48MB ActivityManager.getMemoryClass() Large Heaps ActivityManager.getLargeMemoryClass() Degrades performance
5/27 Embedded Software Lab. Garbage Collection Heap object reference
6/27 Embedded Software Lab. Garbage Collection Bigger heaps cause longer pauses. Pre-Gingerbread GCGingerbread and beyond Stop-the-worldConcurrent(mostly) Full heap collectionPartial collections Pause times is often over 100ms Pause time is usually less than 5ms
7/27 Embedded Software Lab. Bitmaps Old way(pre-Honeycomb) freed via recycle() or finalizer hard to debug full, stop-the-world GCs New way freed synchronously by GC easier to debug concurrent & partial GCs
8/27 Embedded Software Lab. Overview Changes in Gingerbread and Honeycomb heap size Garbage Collection bitmaps Understanding heap usage Logs Memory leaks Eclipse Memory Analyzer(MAT)
9/27 Embedded Software Lab. Interpreting Log Messages Reason for GC GC_CONCURRENT GC_FOR_MALLOC GC_EXTERNAL_ALLOC GC_HPROF_DUMP_HEAP GC_EXPLICIT
10/27 Embedded Software Lab. Interpreting Log Messages Reason for GC Amount freed
11/27 Embedded Software Lab. Interpreting Log Messages Reason for GC Amount freed Heap statistics
12/27 Embedded Software Lab. Interpreting Log Messages Reason for GC Amount freed Heap statistics External memory statistics
13/27 Embedded Software Lab. Interpreting Log Messages Reason for GC Amount freed Heap statistics External memory statistics Pause time
14/27 Embedded Software Lab. Heap Dumps Binary dump of all objects Create with: DDMS android.os.Debug.dumpHprofData() Convert to standard HPROF format: hprof-conv orig.hprof converted.hprof Analyze with MAT, jhat, etc.
15/27 Embedded Software Lab. Memory Leaks Memory Leak? Referencing to an unused object preventing from garbage collecting
16/27 Embedded Software Lab. Eclipse Memory Analyzer(MAT) Download from or Eclipse plug-in is providedhttp://eclipse.org/mat “Shallow heap” and “Retained heap” Shallow heap : just size of object
17/27 Embedded Software Lab. Eclipse Memory Analyzer(MAT) Download from or Eclipse plug-in is providedhttp://eclipse.org/mat “Shallow heap” and “Retained heap” Retained heap : total size of memory after freeing that object
18/27 Embedded Software Lab. Eclipse Memory Analyzer(MAT) Dominator Tree Based on graph theory Dominator: closest object on every path to node A B C E D
19/27 Embedded Software Lab. Heap Dumps : Example com.google.android.apps.maps
20/27 Embedded Software Lab. Heap Dumps : Example
21/27 Embedded Software Lab. Heap Dumps : Example
22/27 Embedded Software Lab. Heap Dumps : Example
23/27 Embedded Software Lab. Heap Dumps : Example
24/27 Embedded Software Lab. Heap Dumps : Example
25/27 Embedded Software Lab. Heap Dumps : Example
26/27 Embedded Software Lab. Heap Dumps : Example
27/27 Embedded Software Lab. Heap Dumps : Example