際際滷

際際滷Share a Scribd company logo
Memory Management
in Android
Hirbod Kamalinia
Keyhan Asghari
Why?
 OutOfMemoryError
 Bad user experiences
 Lags
 ...
Memory Structure
Memory Structure
Memory Handling
 C++, manual handling
 Java, Garbage Collection
 Android, Improved GC
Garbage Collection
GC Roots
Garbage Collection
GC Roots
Garbage Collection
GC Roots
Garbage Collection
GC Roots
Garbage Collection
GC Roots
Everything OK?
NO!
Remaining Problems?
 Memory Churn
 Memory Leak
Memory Leak
GC Roots
Memory Leak
GC Roots
How?
 Concepts
 Useful Tools
Objects in Heap
 Shallow Heap
 Retained Heap
Shallow heap & Retained heap
Shallow heap & Retained heap
100
100
100
100
Shallow heap & Retained heap
100
100
100
100
Shallow heap & Retained heap
100
100
100
100
Retained = 100
Shallow heap & Retained heap
100
100
100
100
Shallow heap & Retained heap
100
100
100
100
Retained = 100
Shallow heap & Retained heap
100
100
100
100
Shallow heap & Retained heap
100
100
100
100
Shallow heap & Retained heap
100
100
100
100
Retained = 100 + 100
Shallow heap & Retained heap
100
100
100
100
Retained = 200
Shallow heap & Retained heap
100
100
100
100
Shallow heap & Retained heap
100
100
100
100
Retained = 100
+ 100
+ 100
+ 100
Shallow heap & Retained heap
100
100
100
100
Retained = 400
Dominator Tree
How to 鍖nd these relations?
Dominator Tree
A
C
B
E
D
Dominator: closest object on every path to node
A
B DC
E
Useful Tools
 Android Studio Memory Monitor
 DDMS Heap tools and Allocation Tracker
 Eclipse Memory Analyzer (MAT)
 ...
Android Studio
Memory Monitor
Android Studio
Memory Monitor
Free and Allocated Memory
Android Studio
Memory Monitor
GC Executions
Android Studio
Memory Monitor
Memory Allocation Level Changed
Memory Allocation Level Changed
Android Studio
Memory Monitor
Call GC Explicitly
Android DDMS
Android DDMS
Useful Tools!
Android DDMS
Call GC Explicitly
Android DDMS
Dump Java Heap
Eclipse Memory Analyzer
(MAT)
DEMO...
What NOT to do?
 Static References
 Inner Classes
 Reference to Context
 Adapters
 ....
Memory matters!
Thanks for your interest...
Useful links
 http://goo.gl/xb57Df
 http://goo.gl/o5O2ON
 http://goo.gl/8BqmCB

More Related Content

Memory management in Android