Fixing Memory Leaks in Android Applications Using DDMS & MAT
Fixing Memory Leaks in Android Applications Using DDMS & MAT
Presented by
Sravankumar Reddy Javaji
CS286 Mobile Programming
Evolution of Devices
Nexus 5 (2013)
2 GB Ram
1920x1080
Heap Size
Heap size is limited and device dependent
G1 = 16 Mb
Droid = 24 Mb
Nexus One = 32 Mb
Xoom = 48 Mb
GalaxyTab = 64 Mb.
ActivityManager.getMemoryClass()
Large Heaps
Honeycomb adds largeHeap option in
AndroidManifest.xml:
- Degrades performance! Use only if you understand why you
need it.
<application
android:name="com.example.foobar"
android:largeHeap="true"
...
</application>
ActivityManager.getLargeMemoryClass()
Garbage Collection
Finding out when the Garbage Collection is run?
- Search for 'GC' or 'gc' in LogCat
How to trigger the Garbage Collection manually?
- System.gc();
Mark and sweepis one of the earliest and bestknowngarbage collection algorithms.
GC Roots
A
C
GC Roots
A
C
GC Roots
A
C
GC Roots
A
C
Bitmaps
Bitmaps take up a lot of memory, especially for rich
images like photographs.
For example, the camera on the Galaxy Nexustakes photos up
to 2592x1936 pixels (5 megapixels). Loading this image into
memory takes about 19MB of memory (2592*1936*4 bytes).
New way:
Bitmaps are saved in Managed (Heap) memory. Freed
synchronously by GC
easier to debug
concurrent & partial GCs
Culprit
Downloading MAT
MAT for Eclipse IDE:http://download.eclipse.org/mat/1.3/update-site
Standalone MAT:- http://www.eclipse.org/mat/
References
http://dubroy.com/blog/google-io-memory-managementfor-android-apps/
https://developer.android.com/training/displayingbitmaps/manage-memory.html
http://macgyverdev.blogspot.com/2011/11/android-trackdown-memory-leaks.html
http://www.brpreiss.com/books/opus5/html/page424.html
https://sites.google.com/site/pyximanew/blog/androidunde
rstandingddmslogcatmemoryoutputmessages
http://www.vogella.com/articles/EclipseMemoryAnalyzer/ar
ticle.html
http://rockgrumbler.blogspot.com/2011/02/commonmemory-leak-causes-in-java.html
Queries. ?
Thank You. !