Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Memory in Android

891 views

Published on

Memory in Android

Published in: Mobile
  • Be the first to comment

Memory in Android

  1. 1. Memory in Android
  2. 2. Agenda • Java Memory Model • java.lang.ref.* • Garbage Collector • Tools • Android Memory Management Tips 2
  3. 3. Java Memory Model Heap Young Generation Eden Space From Space (Survivor1) To Space (Survivor2) Old/Turned Generation Perm Gen Thread 3
  4. 4. … in Android • Heap size limits • ActivityManager.getMemoryClass() • android:largeHeap="true“ • ActivityManager.getLargeMemoryClass() 4
  5. 5. java.lang.ref.* •ReferenceQueue •Reference •WeakReference •SoftReference •PhantomReference 5
  6. 6. Garbage collection 6 Before marking After marking After sweeping Allocator holds a list of references to free spaces, and searches for free space whenever an allocation is required
  7. 7. 7 GC Roots
  8. 8. Log Messages D/dalvikvm: <GC_Reason> <Amount_freed>, <Heap_stats>, <External_memory_stats>, <Pause_time> D/dalvikvm( 9050): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms 8 GC_CONCURRENT GC_FOR_MALLOC GC_HPROF_DUMP_HEAP GC_EXPLICIT GC_EXTERNAL_ALLOC
  9. 9. Tools Demo 9
  10. 10. GC Tips • Know your application • Read the logs • Use MAT 10
  11. 11. Thanks bandysik@gmail.com 11

×