SlideShare a Scribd company logo
1 of 10
Download to read offline
Profiling Memory Usage
of Android Apps


Vivek Jain & Praveen Raj

Geek Night - ThoughtWorks, Pune
Memory Management
• No Page Swap
• LRU cache
Why Manage Memory?
• LRU app (lowmemkiller)
• Apps retaining large chunks of Memory.
• GC cycle is fast.
• OutOfMemory Exception
Garbage Collection
• Type of GC
• Reference counting
• Mark and Sweep
• Mark, Sweep and Compact.
• Android GC is of type. Mark and Sweep(Concurrent)
• Concurrent (Gingerbread and beyond)
GC Root
Mark & Sweep
Memory Leaks
• GC does not prevent memory leaks
• Reference to un-used objects lead to leaks
• Single reference can prevent large group of objects
from being collected
• Common leaks
• Long lived references to Activity/Context or View
objects
Decipher GC messages in
logcat
• Reason

GC_CONCURRENT/GC_FOR_MALLOC/GC_HPROF_DUMP_HEAP/GC_EXPLICIT
• Amount Freed
• Heap Statistics
• External (bitmap, NIO byte buffers) memory statistics
• Pause times
D/dalvikvm( 9050): GC_CONCURRENT freed 2049K, 65% free 3571K/
9991K, external 4703K/5261K, paused 2ms+2ms
Heap Dumps
• Generate using:
• DDMS or IDE (Android Studio / Eclipse)
• Calling android.os.debug.dumpHprofData()
• Convert to standard HPROF format(if required):
• hprof-conv heap-original.hprof heap-converted.hprof
• Analyze with tools like Eclipse MAT
Demo
References and Further
Reading
• Google I/O 2011: Memory management for Android Apps

https://www.youtube.com/watch?v=_CruQY55HOk
• Managing Your App’s Memory

https://developer.android.com/training/articles/memory.html
• Investigating Your RAM Usage

https://developer.android.com/tools/debugging/debugging-memory.html
• Memory Analysis for Android Applications

http://android-developers.blogspot.in/2011/03/memory-analysis-for-
android.html
• Avoiding memory leaks

http://android-developers.blogspot.in/2009/01/avoiding-memory-
leaks.html

More Related Content

Similar to AndroidMemoryProfiling

Similar to AndroidMemoryProfiling (20)

jvm.pptx
jvm.pptxjvm.pptx
jvm.pptx
 
Diagnosing Problems in Production: Cassandra Summit 2014
Diagnosing Problems in Production: Cassandra Summit 2014Diagnosing Problems in Production: Cassandra Summit 2014
Diagnosing Problems in Production: Cassandra Summit 2014
 
Tips from the trenches: Gating Performance
Tips from the trenches: Gating PerformanceTips from the trenches: Gating Performance
Tips from the trenches: Gating Performance
 
淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2
 
Agile startup company management and operation
Agile startup company management and operationAgile startup company management and operation
Agile startup company management and operation
 
Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 
Big server-is-watching-you
Big server-is-watching-youBig server-is-watching-you
Big server-is-watching-you
 
How to Make Norikra Perfect
How to Make Norikra PerfectHow to Make Norikra Perfect
How to Make Norikra Perfect
 
this-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptxthis-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptx
 
Webinar: Diagnosing Apache Cassandra Problems in Production
Webinar: Diagnosing Apache Cassandra Problems in ProductionWebinar: Diagnosing Apache Cassandra Problems in Production
Webinar: Diagnosing Apache Cassandra Problems in Production
 
Webinar: Diagnosing Apache Cassandra Problems in Production
Webinar: Diagnosing Apache Cassandra Problems in ProductionWebinar: Diagnosing Apache Cassandra Problems in Production
Webinar: Diagnosing Apache Cassandra Problems in Production
 
GIS User to Web-GIS Developer Journey
GIS User to Web-GIS Developer JourneyGIS User to Web-GIS Developer Journey
GIS User to Web-GIS Developer Journey
 
millions-gc-jax-2022.pptx
millions-gc-jax-2022.pptxmillions-gc-jax-2022.pptx
millions-gc-jax-2022.pptx
 
Web Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity ConferenceWeb Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity Conference
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012
 
Suning OpenStack Cloud and Heat
Suning OpenStack Cloud and HeatSuning OpenStack Cloud and Heat
Suning OpenStack Cloud and Heat
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展
 
DOTNET8.pptx
DOTNET8.pptxDOTNET8.pptx
DOTNET8.pptx
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 

AndroidMemoryProfiling

  • 1. Profiling Memory Usage of Android Apps 
 Vivek Jain & Praveen Raj
 Geek Night - ThoughtWorks, Pune
  • 2. Memory Management • No Page Swap • LRU cache
  • 3. Why Manage Memory? • LRU app (lowmemkiller) • Apps retaining large chunks of Memory. • GC cycle is fast. • OutOfMemory Exception
  • 4. Garbage Collection • Type of GC • Reference counting • Mark and Sweep • Mark, Sweep and Compact. • Android GC is of type. Mark and Sweep(Concurrent) • Concurrent (Gingerbread and beyond)
  • 6. Memory Leaks • GC does not prevent memory leaks • Reference to un-used objects lead to leaks • Single reference can prevent large group of objects from being collected • Common leaks • Long lived references to Activity/Context or View objects
  • 7. Decipher GC messages in logcat • Reason
 GC_CONCURRENT/GC_FOR_MALLOC/GC_HPROF_DUMP_HEAP/GC_EXPLICIT • Amount Freed • Heap Statistics • External (bitmap, NIO byte buffers) memory statistics • Pause times D/dalvikvm( 9050): GC_CONCURRENT freed 2049K, 65% free 3571K/ 9991K, external 4703K/5261K, paused 2ms+2ms
  • 8. Heap Dumps • Generate using: • DDMS or IDE (Android Studio / Eclipse) • Calling android.os.debug.dumpHprofData() • Convert to standard HPROF format(if required): • hprof-conv heap-original.hprof heap-converted.hprof • Analyze with tools like Eclipse MAT
  • 10. References and Further Reading • Google I/O 2011: Memory management for Android Apps
 https://www.youtube.com/watch?v=_CruQY55HOk • Managing Your App’s Memory
 https://developer.android.com/training/articles/memory.html • Investigating Your RAM Usage
 https://developer.android.com/tools/debugging/debugging-memory.html • Memory Analysis for Android Applications
 http://android-developers.blogspot.in/2011/03/memory-analysis-for- android.html • Avoiding memory leaks
 http://android-developers.blogspot.in/2009/01/avoiding-memory- leaks.html