SlideShare a Scribd company logo
1 of 21
Download to read offline
Eclipse Memory Analyzer
          Tool
      Lakshman Kakkirala
         little eye labs
Agenda
●   Memory Analysis
●   Some Definitions
●   An example leak code
●   Demo of MAT and some basic functionality
Prereqs
● Android app development
● Basic Heap and Garbage Collection

Disqualification
● Advanced knowledge of MAT :-)
littleEye appInsight

CT Scanner for your app
 http://www.littleeye.co
Why Memory Analysis?
● Identify Leaks
● Reduce memory footprint
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
Some definitions

●   Shallow Size
●   Retained Size
●   Dominator
●   Dominator Tree
●   GCRoots
Example - Object Graph
                          E
                 B       100
                100      100
                300

   A                      F
  100                    100
                 C       100
  600
               100
               200         D
                         100
                         100
Example (contd) - Dominator Tree

                             E
                 B

                             F

   A

                C                D
Example - Memory Leak
public class MainActivity extends Activity {
  private static LeakClass leak;

    // *NOT A STATIC*
    class LeakClass { }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        ....
      if (leak == null) {
             leak = new LeakClass();
      }
        ...
    }
}
Investigation Tools - LogCat
● D/dalvikvm( 9050 ): GC_CONCURRENT
  freed 2049K, 65% free 3571K/9991K,
  external 4703K/5261K, paused 2ms+2ms
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)
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
Demo
Covering
● View Dominator Tree
● Inspector
  ○ look at the field values
  ○ browse through entries in a Collection
● Class Histograms
● Group by Value
Demo (contd...)
●   Immediate Dominators
●   Path from GC roots
●   Retained Set
●   Object Query Language
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/
Backup Slides
Application Attributes:
<application
 android:largeHeap="true">
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
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
Typical Garbage Collections
GC_CONCURRENT
GC_FOR_MALLOC
GC_EXTERNAL_ALLOC (pre-honeycomb)
GC_HPROF_DUMP_HEAP
GC_EXPLICIT - app calling System.gc()

More Related Content

What's hot

Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List Hitesh-Java
 
Session 20 - Collections - Maps
Session 20 - Collections - MapsSession 20 - Collections - Maps
Session 20 - Collections - MapsPawanMM
 
Session 14 - Object Class
Session 14 - Object ClassSession 14 - Object Class
Session 14 - Object ClassPawanMM
 
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)Jannat Ruma
 
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Jannat Ruma
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)Jannat Ruma
 
KafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF filesKafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF filesRubén Izquierdo Beviá
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakensRichardWarburton
 
CLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRFCLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRFRubén Izquierdo Beviá
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingGurpreet singh
 
Performance and predictability
Performance and predictabilityPerformance and predictability
Performance and predictabilityRichardWarburton
 
Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Hitesh-Java
 
Performance and predictability (1)
Performance and predictability (1)Performance and predictability (1)
Performance and predictability (1)RichardWarburton
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object SerializationNavneet Prakash
 
SQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxesSQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxesJasmine Chen
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserializationYoung Alista
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps Hitesh-Java
 

What's hot (20)

Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
Session 20 - Collections - Maps
Session 20 - Collections - MapsSession 20 - Collections - Maps
Session 20 - Collections - Maps
 
Object Class
Object Class Object Class
Object Class
 
Session 14 - Object Class
Session 14 - Object ClassSession 14 - Object Class
Session 14 - Object Class
 
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
 
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
 
KafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF filesKafNafParserPy: a python library for parsing/creating KAF and NAF files
KafNafParserPy: a python library for parsing/creating KAF and NAF files
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakens
 
CLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRFCLTL presentation: training an opinion mining system from KAF files using CRF
CLTL presentation: training an opinion mining system from KAF files using CRF
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Performance and predictability
Performance and predictabilityPerformance and predictability
Performance and predictability
 
Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics
 
Performance and predictability (1)
Performance and predictability (1)Performance and predictability (1)
Performance and predictability (1)
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object Serialization
 
SQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxesSQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxes
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 

Viewers also liked

Energy efficiency of android
Energy efficiency of androidEnergy efficiency of android
Energy efficiency of androidlittleeye
 
Virtualization aware Java VM
Virtualization aware Java VMVirtualization aware Java VM
Virtualization aware Java VMTim Ellison
 
Introduction to OpenStack
Introduction to OpenStackIntroduction to OpenStack
Introduction to OpenStackjamiehannaford
 
Compaction and Splitting in Apache Accumulo
Compaction and Splitting in Apache AccumuloCompaction and Splitting in Apache Accumulo
Compaction and Splitting in Apache AccumuloHortonworks
 
OSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration SummitOSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration SummitDon Marti
 
Virtualization Primer for Java Developers
Virtualization Primer for Java DevelopersVirtualization Primer for Java Developers
Virtualization Primer for Java DevelopersRichard McDougall
 
Exploring Ketai Library, Droidcon
Exploring Ketai Library, DroidconExploring Ketai Library, Droidcon
Exploring Ketai Library, Droidconsriram_iyengar
 
OSv at Cassandra Summit
OSv at Cassandra SummitOSv at Cassandra Summit
OSv at Cassandra SummitDon Marti
 
Microservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureKelly Goetsch
 

Viewers also liked (10)

Energy efficiency of android
Energy efficiency of androidEnergy efficiency of android
Energy efficiency of android
 
Virtualization aware Java VM
Virtualization aware Java VMVirtualization aware Java VM
Virtualization aware Java VM
 
Introduction to OpenStack
Introduction to OpenStackIntroduction to OpenStack
Introduction to OpenStack
 
Compaction and Splitting in Apache Accumulo
Compaction and Splitting in Apache AccumuloCompaction and Splitting in Apache Accumulo
Compaction and Splitting in Apache Accumulo
 
OSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration SummitOSv presentation from Linux Foundation Collaboration Summit
OSv presentation from Linux Foundation Collaboration Summit
 
Virtualization Primer for Java Developers
Virtualization Primer for Java DevelopersVirtualization Primer for Java Developers
Virtualization Primer for Java Developers
 
Unik Slides
Unik SlidesUnik Slides
Unik Slides
 
Exploring Ketai Library, Droidcon
Exploring Ketai Library, DroidconExploring Ketai Library, Droidcon
Exploring Ketai Library, Droidcon
 
OSv at Cassandra Summit
OSv at Cassandra SummitOSv at Cassandra Summit
OSv at Cassandra Summit
 
Microservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright Future
 

Similar to Eclipse Memory Analyzer Tool

Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_appsBin Shao
 
Effective memory management
Effective memory managementEffective memory management
Effective memory managementYurii Kotov
 
Effective memory management
Effective memory managementEffective memory management
Effective memory managementDenis Zhuchinski
 
Garbage collectors and Memory Leaks in Nodejs - V8
Garbage collectors and Memory Leaks in Nodejs - V8Garbage collectors and Memory Leaks in Nodejs - V8
Garbage collectors and Memory Leaks in Nodejs - V8Thien Ly
 
"Avoiding memory leaks in Android" Денис Жучинский
"Avoiding memory leaks in Android" Денис Жучинский"Avoiding memory leaks in Android" Денис Жучинский
"Avoiding memory leaks in Android" Денис ЖучинскийFwdays
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalNAVER D2
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
Hildon Desktop Widgets by Dimitry Pastushenko
Hildon Desktop Widgets by Dimitry PastushenkoHildon Desktop Widgets by Dimitry Pastushenko
Hildon Desktop Widgets by Dimitry PastushenkoAshley Walker
 
Scio - A Scala API for Google Cloud Dataflow & Apache Beam
Scio - A Scala API for Google Cloud Dataflow & Apache BeamScio - A Scala API for Google Cloud Dataflow & Apache Beam
Scio - A Scala API for Google Cloud Dataflow & Apache BeamNeville Li
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSNicolas Embleton
 
Docker slides
Docker slidesDocker slides
Docker slidesAyla Khan
 
Post mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EUPost mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EUMichael Dawson
 
Performance #1: Memory
Performance #1: MemoryPerformance #1: Memory
Performance #1: MemoryYonatan Levin
 
Queue in the cloud with mongo db
Queue in the cloud with mongo dbQueue in the cloud with mongo db
Queue in the cloud with mongo dbNuri Halperin
 
MongoDB as a Cloud Queue
MongoDB as a Cloud QueueMongoDB as a Cloud Queue
MongoDB as a Cloud QueueMongoDB
 

Similar to Eclipse Memory Analyzer Tool (20)

Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_apps
 
Effective memory management
Effective memory managementEffective memory management
Effective memory management
 
Effective memory management
Effective memory managementEffective memory management
Effective memory management
 
Garbage collectors and Memory Leaks in Nodejs - V8
Garbage collectors and Memory Leaks in Nodejs - V8Garbage collectors and Memory Leaks in Nodejs - V8
Garbage collectors and Memory Leaks in Nodejs - V8
 
"Avoiding memory leaks in Android" Денис Жучинский
"Avoiding memory leaks in Android" Денис Жучинский"Avoiding memory leaks in Android" Денис Жучинский
"Avoiding memory leaks in Android" Денис Жучинский
 
Openstack 簡介
Openstack 簡介Openstack 簡介
Openstack 簡介
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
Hildon Desktop Widgets by Dimitry Pastushenko
Hildon Desktop Widgets by Dimitry PastushenkoHildon Desktop Widgets by Dimitry Pastushenko
Hildon Desktop Widgets by Dimitry Pastushenko
 
Performance #1 memory
Performance #1   memoryPerformance #1   memory
Performance #1 memory
 
Scio - A Scala API for Google Cloud Dataflow & Apache Beam
Scio - A Scala API for Google Cloud Dataflow & Apache BeamScio - A Scala API for Google Cloud Dataflow & Apache Beam
Scio - A Scala API for Google Cloud Dataflow & Apache Beam
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JS
 
Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013
 
Varnish - PLNOG 4
Varnish - PLNOG 4Varnish - PLNOG 4
Varnish - PLNOG 4
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
Docker slides
Docker slidesDocker slides
Docker slides
 
Post mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EUPost mortem talk - Node Interactive EU
Post mortem talk - Node Interactive EU
 
Performance #1: Memory
Performance #1: MemoryPerformance #1: Memory
Performance #1: Memory
 
Queue in the cloud with mongo db
Queue in the cloud with mongo dbQueue in the cloud with mongo db
Queue in the cloud with mongo db
 
MongoDB as a Cloud Queue
MongoDB as a Cloud QueueMongoDB as a Cloud Queue
MongoDB as a Cloud Queue
 

Eclipse Memory Analyzer Tool

  • 1. Eclipse Memory Analyzer Tool Lakshman Kakkirala little eye labs
  • 2. Agenda ● Memory Analysis ● Some Definitions ● An example leak code ● Demo of MAT and some basic functionality
  • 3. Prereqs ● Android app development ● Basic Heap and Garbage Collection Disqualification ● Advanced knowledge of MAT :-)
  • 4. littleEye appInsight CT Scanner for your app http://www.littleeye.co
  • 5. Why Memory Analysis? ● Identify Leaks ● Reduce memory footprint
  • 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
  • 9. Example (contd) - Dominator Tree E B F A C D
  • 10. Example - Memory Leak public class MainActivity extends Activity { private static LeakClass leak; // *NOT A STATIC* class LeakClass { } @Override public void onCreate(Bundle savedInstanceState) { .... if (leak == null) { leak = new LeakClass(); } ... } }
  • 11. Investigation Tools - LogCat ● D/dalvikvm( 9050 ): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms
  • 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/
  • 17.
  • 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
  • 21. Typical Garbage Collections GC_CONCURRENT GC_FOR_MALLOC GC_EXTERNAL_ALLOC (pre-honeycomb) GC_HPROF_DUMP_HEAP GC_EXPLICIT - app calling System.gc()