SlideShare a Scribd company logo
Android Crash Analysis and The Dalvik
Garbage Collector - Tips
Oren BarAd
Mobile Security Team Leader
AVG
2
100,000,000
3
Intro
• App on the market
• Crashes will happen
• Need to Fix the Bugs!
• Identify the root issues
4
Who?
• Developing for Android since 2008
• The first employee of DroidSecurity
– First company to release An antivirus to the Android
market (2009)
– Later acquired by AVG (2011)
• Mobile Security Research Team Leader @AVG
• B.Sc Information System Engineering from BGU
5
Agenda
• Android app crash Collection & Analysis
• The Android Garbage Collector
• Memory analysis Tools
• Tips and tricks
6
How to collect crash information?
7
What to fix first?
• Easy to fix
• Affects most users
• The ones users complain most about
• Affects the most popular device
8
Root cause analysis
• Stare at data:
–Crash type
–Exception Type
–Device
–Manufacturer
–OS version
–Locale
• And stare some more…
9
Ultimate debugging method!
• What is the answer to this bug?
– 42
• We don’t know the answer
– Brainstorming
– Developing tools
• Learning something new…
10
Root cause analysis – Real world example
• Concurrent.Timeout exception
– ~10% of total crashes for AVG antivirus.
– Unhelpful stack traces
– Second place in top 10 crashes (and number 5, and number 9)
java.util.concurrent.TimeoutException: android.os.BinderProxy.finalize() timed out after 10
seconds
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:401)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
at java.lang.Thread.run(Thread.java:841)
java.util.concurrent.TimeoutException: com.android.internal.os.BinderInternal$GcWatcher.finalize() timed out after 10 seconds
java.util.concurrent.TimeoutException: android.os.Parcel.finalize() timed out after 10 seconds
java.util.concurrent.TimeoutException: java.io.FileInputStream.finalize() timed out after 10 seconds
11
Device and OS analysis
33%
66%
Device
Galaxy S3
49%
38%
13%
19%
10%
71%
OS
Crash Dashboard
4.2.2
4.3
Other OS
Versions
12
What next?
• After going deep into the Code…
• Get S3 and use
13
Android GC – little bit of history
Gingerbread
14
Complex
Object
Tricolor collector at work
roots rootsroots
object object object
object object object
object
object
object object
15
object
Tricolor collector at work
roots rootsroots
object object object
object object object
object
object
object object
16
object
Tricolor collector at work
roots rootsroots
object object object
object object object
object
object
object object
17
object
Tricolor collector at work
roots rootsroots
object object object
object object object
object
object
object object
18
Complex
Object
Tricolor collector at work
roots rootsroots
object object object
object object object
object
object
object object
19
Complex
Object
Tricolor collector at work
roots rootsroots
object object object
object object object
object
object
object object
20
Garbage collector observed behavior
Cause Effect
GC_FOR_MALLOC Stop The world GC
Use complex Objects GC takes longer
A lot of small objects GC take Longer
Use more memory GC takes longer
USE_LARGE_HEAP All of the above
21
Trying to replicate the problem
• The GC_Test project
– Test the GC performance under load
– Android app to test the behavior of the GC on android
– https://github.com/oba2cat3/GCTest
• Useful logcat python script
– https://github.com/oba2cat3/logcat2memorygraph
• Available from GitHub
22
Logcat output
02-04 12:40:33.185: D/dalvikvm(2496): GC_EXPLICIT freed <1K, 19% free 14383K/17720K, paused 1ms+1ms, total 17ms
02-04 12:40:33.265: D/dalvikvm(3279): GC_CONCURRENT freed 661K, 27% free 14934K/20336K, paused 5ms+3ms, total 21ms
02-04 12:40:33.460: D/dalvikvm(5637): GC_CONCURRENT freed 834K, 22% free 15516K/19644K, paused 6ms+3ms, total 33ms
02-04 12:40:33.480: D/dalvikvm(3279): GC_CONCURRENT freed 313K, 27% free 15022K/20336K, paused 3ms+9ms, total 30ms
02-04 12:40:33.665: D/dalvikvm(5637): GC_CONCURRENT freed 369K, 21% free 15658K/19644K, paused 2ms+2ms, total 18ms
02-04 12:40:33.725: D/dalvikvm(5730): GC_CONCURRENT freed 1166K, 23% free 15188K/19644K, paused 4ms+2ms, total 25ms
02-04 12:40:33.765: D/dalvikvm(5637): GC_CONCURRENT freed 430K, 20% free 15740K/19644K, paused 7ms+2ms, total 22ms
02-04 12:40:33.865: D/dalvikvm(5730): GC_CONCURRENT freed 325K, 23% free 15256K/19644K, paused 2ms+3ms, total 22ms
02-04 12:40:34.065: D/dalvikvm(5637): GC_CONCURRENT freed 1811K, 25% free 15934K/21040K, paused 3ms+2ms, total 29ms
02-04 12:40:34.160: D/dalvikvm(5637): GC_CONCURRENT freed 99K, 23% free 16354K/21040K, paused 2ms+4ms, total 31ms
02-04 12:40:34.250: D/dalvikvm(3403): GC_EXPLICIT freed 172K, 24% free 14956K/19628K, paused 3ms+4ms, total 28ms
02-04 12:40:34.315: D/dalvikvm(5766): GC_CONCURRENT freed 1185K, 23% free 15148K/19628K, paused 3ms+3ms, total 28ms
02-04 12:40:34.350: D/dalvikvm(5637): GC_CONCURRENT freed 1140K, 26% free 15766K/21040K, paused 3ms+3ms, total 30ms
02-04 12:40:34.495: D/dalvikvm(4155): GC_CONCURRENT freed 1274K, 24% free 15093K/19660K, paused 7ms+5ms, total 56ms
02-04 12:40:34.635: D/dalvikvm(3333): GC_CONCURRENT freed 574K, 24% free 14982K/19620K, paused 3ms+2ms, total 19ms
02-04 12:40:34.780: D/dalvikvm(5694): GC_CONCURRENT freed 1268K, 24% free 15100K/19656K, paused 3ms+1ms, total 25ms
02-04 12:40:34.840: D/dalvikvm(2960): GC_EXPLICIT freed 1236K, 10% free 53524K/58860K, paused 4ms+7ms, total 130ms
02-04 12:40:34.915: D/dalvikvm(5637): GC_FOR_ALLOC freed 143K, 25% free 15978K/21040K, paused 26ms, total 26ms
02-04 12:40:33.480: D/dalvikvm(3279): GC_CONCURRENT freed 313K, 27% free 15022K/20336K, paused 3ms+9ms, total 30ms
02-04 12:40:33.665: D/dalvikvm(5637): GC_CONCURRENT freed 369K, 21% free 15658K/19644K, paused 2ms+2ms, total 18ms
02-04 12:40:33.725: D/dalvikvm(5730): GC_CONCURRENT freed 1166K, 23% free 15188K/19644K, paused 4ms+2ms, total 25ms
02-04 12:40:33.765: D/dalvikvm(5637): GC_CONCURRENT freed 430K, 20% free 15740K/19644K, paused 7ms+2ms, total 22ms
02-04 12:40:33.865: D/dalvikvm(5730): GC_CONCURRENT freed 325K, 23% free 15256K/19644K, paused 2ms+3ms, total 22ms
02-04 12:40:34.065: D/dalvikvm(5637): GC_CONCURRENT freed 1811K, 25% free 15934K/21040K, paused 3ms+2ms, total 29ms
23
Script result - Heap size and GC delays
0
0.2
0.4
0.6
0.8
1
1.2
0
20000
40000
60000
80000
100000
120000
140000
160000
Time in MSheap size in KB
dalvikvm event timestamps
current heap
max heap
24
Script result - Heap size and GC delays
0
50
100
150
200
250
300
350
400
0
20000
40000
60000
80000
100000
120000
140000
160000
Time in MSheap size in KB
dalvikvm event timestamps
current heap
max heap
ui pause time
total pause
25
Script result - Heap size and GC delays
0
50
100
150
200
250
300
350
400
0
20000
40000
60000
80000
100000
120000
140000
160000
Time in MSheap size in KB
dalvikvm event timestamps
current heap
max heap
ui pause time
total pause
webview
start
26
Memory Analyzer Tool tricks
27
Memory Analyzer Tool tricks
28
Memory Analyzer Tool tricks
29
Memory Analyzer Tool tricks
30
Memory Analyzer Tool tricks
31
Memory Analyzer Tool tricks
32
Memory Analyzer Tool tricks
33
Memory Analyzer Tool tricks
34
Tips for managing GC
Do How
Avoid GC_FOR_ALLOC Load stuff in Splash
Use Object Pools For large/heavy objects
Avoid Complex Objects Use simpler Objects
Perform Heap analysis Use MAT and DDMS
Reduce memory use …
35
Summary
• Application will crash
–Collect and Analyze
–Understand and Fix
• Fixing the bug is half the fun
36
Back to the problem
• JNI objects are a special case
• Dalvik will finalize and Destroy
• Timeouts will happen... And they Do!
37
Q&A
• Questions?
• Contact: Oren.barad@avg.com
• We are hiring!
• Come talk to us in the AVG booth
38
Links and resources
• http://android-developers.blogspot.co.il/2011/03/memory-
analysis-for-android.html
• http://www.brpreiss.com/books/opus5/html/page424.html
• http://java-is-the-new-c.blogspot.co.il/2013/07/tuning-and-
benchmarking-java-7s-garbage.html
• http://www.slideshare.net/muhammedshakirmisarwala/java-
performance-monitoring-tuning
• http://www.slideshare.net/VikasBalikai/gc-in-android
• http://www.javacodegeeks.com/2012/01/practical-garbage-
collection-part-1.html
39
Links and resources
• https://android.googlesource.com/platform/dalvik/+/android-
4.3_r2/vm/alloc/MarkSweep.cpp
• https://android.googlesource.com/platform/dalvik/+log/android-
4.4.2_r2/vm/alloc/MarkSweep.cpp
• https://android.googlesource.com/platform/dalvik/+/gingerbread/vm/alloc/MarkSwe
ep.c
• https://android.googlesource.com/platform/dalvik/+/froyo-
release/vm/alloc/MarkSweep.c

More Related Content

PPTX
GitHub Presentation
PPT
Ios development
PPTX
Introduction to Flutter
PDF
Alfresco 5.2 REST API
 
PDF
Microservices
PPTX
What is Flutter
PPT
DevOps Explained
PDF
OPENSHIFT CONTAINER PLATFORM CI/CD Build & Deploy
GitHub Presentation
Ios development
Introduction to Flutter
Alfresco 5.2 REST API
 
Microservices
What is Flutter
DevOps Explained
OPENSHIFT CONTAINER PLATFORM CI/CD Build & Deploy

What's hot (20)

PPTX
PPTX
Android application development ppt
PDF
Jenkins
PPTX
Flutter introduction
PDF
Designing a complete ci cd pipeline using argo events, workflow and cd products
PPTX
Flutter introduction
PPSX
Introduction to mobile application
PDF
Introduction to GitHub Actions
PDF
Making a Headless Android Device
PDF
Introduction to CICD
PPTX
Git Lab Introduction
PDF
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
PDF
Git 101: Git and GitHub for Beginners
PPTX
Container based CI/CD on GitHub Actions
PDF
Getting started with flutter
PDF
Advanced Git
PPTX
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
PPTX
2014 Target Case Competition
PPTX
Git basics to advance with diagrams
PDF
API Governance
Android application development ppt
Jenkins
Flutter introduction
Designing a complete ci cd pipeline using argo events, workflow and cd products
Flutter introduction
Introduction to mobile application
Introduction to GitHub Actions
Making a Headless Android Device
Introduction to CICD
Git Lab Introduction
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
Git 101: Git and GitHub for Beginners
Container based CI/CD on GitHub Actions
Getting started with flutter
Advanced Git
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
2014 Target Case Competition
Git basics to advance with diagrams
API Governance
Ad

Viewers also liked (13)

ODP
Android crash debugging
PDF
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
PPTX
Murali_BlockChain_Technology_6_May_2016.pptx
PDF
iOS Mobile App crash - Analysis
ODP
Inter-process communication of Android
PDF
Memory leak patterns in javascript
PDF
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
PDF
ADB(Android Debug Bridge): How it works?
PPT
Android Debug
PDF
Understanding the Android System Server
PDF
Android IPC Mechanism
PDF
Embedded Android Workshop with Nougat
PPTX
Overview of Android binder IPC implementation
Android crash debugging
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Murali_BlockChain_Technology_6_May_2016.pptx
iOS Mobile App crash - Analysis
Inter-process communication of Android
Memory leak patterns in javascript
Android internals 10 - Debugging/Profiling, Bluetooth/WiFI/RIL (rev_1.1)
ADB(Android Debug Bridge): How it works?
Android Debug
Understanding the Android System Server
Android IPC Mechanism
Embedded Android Workshop with Nougat
Overview of Android binder IPC implementation
Ad

Similar to Android Crash analysis and The Dalvik Garbage collector – Tools and Tips (20)

PDF
Memory management for_android_apps
PDF
performance optimization: Memory
PDF
Eclipse Memory Analyzer Tool
PDF
Memory Leaks in Android Applications
PDF
Effective memory management
PDF
Effective memory management
PDF
Performance #1: Memory
PPTX
Performance #1 memory
PDF
"Avoiding memory leaks in Android" Денис Жучинский
PDF
X Means Y
PDF
Memory management
PPT
Memory problems in android programming
PDF
Android Meetup Slovenia #5 - Don't go crashing my heart by Zeljko Plesac, Inf...
PDF
Android Memory , Where is all My RAM
ODP
Memory management
PPTX
Memory management in Andoid
PPTX
GC Tuning & Troubleshooting Crash Course
ODT
ACADGILD:: ANDROID LESSON-How to analyze &amp; manage memory on android like ...
PDF
Crash Wars - The handling awakens
PPTX
Memory Usage in Android
Memory management for_android_apps
performance optimization: Memory
Eclipse Memory Analyzer Tool
Memory Leaks in Android Applications
Effective memory management
Effective memory management
Performance #1: Memory
Performance #1 memory
"Avoiding memory leaks in Android" Денис Жучинский
X Means Y
Memory management
Memory problems in android programming
Android Meetup Slovenia #5 - Don't go crashing my heart by Zeljko Plesac, Inf...
Android Memory , Where is all My RAM
Memory management
Memory management in Andoid
GC Tuning & Troubleshooting Crash Course
ACADGILD:: ANDROID LESSON-How to analyze &amp; manage memory on android like ...
Crash Wars - The handling awakens
Memory Usage in Android

More from DroidConTLV (20)

PDF
Mobile Development in the Information Age - Yossi Elkrief, Nike
PDF
Doing work in the background - Darryn Campbell, Zebra Technologies
PDF
No more video loss - Alex Rivkin, Motorola Solutions
PDF
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
PDF
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
PDF
MVVM In real life - Lea Cohen Tannoudji, Lightricks
PDF
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
PDF
Building Apps with Flutter - Hillel Coren, Invoice Ninja
PDF
New Android Project: The Most Important Decisions - Vasiliy Zukanov
PDF
Designing a Design System - Shai Mishali, Gett
PDF
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
PDF
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
PDF
Flutter State Management - Moti Bartov, Tikal
PDF
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
PDF
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
PDF
DroidconTLV 2019
PDF
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
PDF
Introduction to React Native - Lev Vidrak, Wix
PDF
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
PDF
Educating your app – adding ML edge to your apps - Maoz Tamir
Mobile Development in the Information Age - Yossi Elkrief, Nike
Doing work in the background - Darryn Campbell, Zebra Technologies
No more video loss - Alex Rivkin, Motorola Solutions
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
MVVM In real life - Lea Cohen Tannoudji, Lightricks
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Building Apps with Flutter - Hillel Coren, Invoice Ninja
New Android Project: The Most Important Decisions - Vasiliy Zukanov
Designing a Design System - Shai Mishali, Gett
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Flutter State Management - Moti Bartov, Tikal
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
DroidconTLV 2019
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Introduction to React Native - Lev Vidrak, Wix
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Educating your app – adding ML edge to your apps - Maoz Tamir

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
sap open course for s4hana steps from ECC to s4
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
Programs and apps: productivity, graphics, security and other tools

Android Crash analysis and The Dalvik Garbage collector – Tools and Tips

  • 1. Android Crash Analysis and The Dalvik Garbage Collector - Tips Oren BarAd Mobile Security Team Leader AVG
  • 3. 3 Intro • App on the market • Crashes will happen • Need to Fix the Bugs! • Identify the root issues
  • 4. 4 Who? • Developing for Android since 2008 • The first employee of DroidSecurity – First company to release An antivirus to the Android market (2009) – Later acquired by AVG (2011) • Mobile Security Research Team Leader @AVG • B.Sc Information System Engineering from BGU
  • 5. 5 Agenda • Android app crash Collection & Analysis • The Android Garbage Collector • Memory analysis Tools • Tips and tricks
  • 6. 6 How to collect crash information?
  • 7. 7 What to fix first? • Easy to fix • Affects most users • The ones users complain most about • Affects the most popular device
  • 8. 8 Root cause analysis • Stare at data: –Crash type –Exception Type –Device –Manufacturer –OS version –Locale • And stare some more…
  • 9. 9 Ultimate debugging method! • What is the answer to this bug? – 42 • We don’t know the answer – Brainstorming – Developing tools • Learning something new…
  • 10. 10 Root cause analysis – Real world example • Concurrent.Timeout exception – ~10% of total crashes for AVG antivirus. – Unhelpful stack traces – Second place in top 10 crashes (and number 5, and number 9) java.util.concurrent.TimeoutException: android.os.BinderProxy.finalize() timed out after 10 seconds at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:401) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73) at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170) at java.lang.Thread.run(Thread.java:841) java.util.concurrent.TimeoutException: com.android.internal.os.BinderInternal$GcWatcher.finalize() timed out after 10 seconds java.util.concurrent.TimeoutException: android.os.Parcel.finalize() timed out after 10 seconds java.util.concurrent.TimeoutException: java.io.FileInputStream.finalize() timed out after 10 seconds
  • 11. 11 Device and OS analysis 33% 66% Device Galaxy S3 49% 38% 13% 19% 10% 71% OS Crash Dashboard 4.2.2 4.3 Other OS Versions
  • 12. 12 What next? • After going deep into the Code… • Get S3 and use
  • 13. 13 Android GC – little bit of history Gingerbread
  • 14. 14 Complex Object Tricolor collector at work roots rootsroots object object object object object object object object object object
  • 15. 15 object Tricolor collector at work roots rootsroots object object object object object object object object object object
  • 16. 16 object Tricolor collector at work roots rootsroots object object object object object object object object object object
  • 17. 17 object Tricolor collector at work roots rootsroots object object object object object object object object object object
  • 18. 18 Complex Object Tricolor collector at work roots rootsroots object object object object object object object object object object
  • 19. 19 Complex Object Tricolor collector at work roots rootsroots object object object object object object object object object object
  • 20. 20 Garbage collector observed behavior Cause Effect GC_FOR_MALLOC Stop The world GC Use complex Objects GC takes longer A lot of small objects GC take Longer Use more memory GC takes longer USE_LARGE_HEAP All of the above
  • 21. 21 Trying to replicate the problem • The GC_Test project – Test the GC performance under load – Android app to test the behavior of the GC on android – https://github.com/oba2cat3/GCTest • Useful logcat python script – https://github.com/oba2cat3/logcat2memorygraph • Available from GitHub
  • 22. 22 Logcat output 02-04 12:40:33.185: D/dalvikvm(2496): GC_EXPLICIT freed <1K, 19% free 14383K/17720K, paused 1ms+1ms, total 17ms 02-04 12:40:33.265: D/dalvikvm(3279): GC_CONCURRENT freed 661K, 27% free 14934K/20336K, paused 5ms+3ms, total 21ms 02-04 12:40:33.460: D/dalvikvm(5637): GC_CONCURRENT freed 834K, 22% free 15516K/19644K, paused 6ms+3ms, total 33ms 02-04 12:40:33.480: D/dalvikvm(3279): GC_CONCURRENT freed 313K, 27% free 15022K/20336K, paused 3ms+9ms, total 30ms 02-04 12:40:33.665: D/dalvikvm(5637): GC_CONCURRENT freed 369K, 21% free 15658K/19644K, paused 2ms+2ms, total 18ms 02-04 12:40:33.725: D/dalvikvm(5730): GC_CONCURRENT freed 1166K, 23% free 15188K/19644K, paused 4ms+2ms, total 25ms 02-04 12:40:33.765: D/dalvikvm(5637): GC_CONCURRENT freed 430K, 20% free 15740K/19644K, paused 7ms+2ms, total 22ms 02-04 12:40:33.865: D/dalvikvm(5730): GC_CONCURRENT freed 325K, 23% free 15256K/19644K, paused 2ms+3ms, total 22ms 02-04 12:40:34.065: D/dalvikvm(5637): GC_CONCURRENT freed 1811K, 25% free 15934K/21040K, paused 3ms+2ms, total 29ms 02-04 12:40:34.160: D/dalvikvm(5637): GC_CONCURRENT freed 99K, 23% free 16354K/21040K, paused 2ms+4ms, total 31ms 02-04 12:40:34.250: D/dalvikvm(3403): GC_EXPLICIT freed 172K, 24% free 14956K/19628K, paused 3ms+4ms, total 28ms 02-04 12:40:34.315: D/dalvikvm(5766): GC_CONCURRENT freed 1185K, 23% free 15148K/19628K, paused 3ms+3ms, total 28ms 02-04 12:40:34.350: D/dalvikvm(5637): GC_CONCURRENT freed 1140K, 26% free 15766K/21040K, paused 3ms+3ms, total 30ms 02-04 12:40:34.495: D/dalvikvm(4155): GC_CONCURRENT freed 1274K, 24% free 15093K/19660K, paused 7ms+5ms, total 56ms 02-04 12:40:34.635: D/dalvikvm(3333): GC_CONCURRENT freed 574K, 24% free 14982K/19620K, paused 3ms+2ms, total 19ms 02-04 12:40:34.780: D/dalvikvm(5694): GC_CONCURRENT freed 1268K, 24% free 15100K/19656K, paused 3ms+1ms, total 25ms 02-04 12:40:34.840: D/dalvikvm(2960): GC_EXPLICIT freed 1236K, 10% free 53524K/58860K, paused 4ms+7ms, total 130ms 02-04 12:40:34.915: D/dalvikvm(5637): GC_FOR_ALLOC freed 143K, 25% free 15978K/21040K, paused 26ms, total 26ms 02-04 12:40:33.480: D/dalvikvm(3279): GC_CONCURRENT freed 313K, 27% free 15022K/20336K, paused 3ms+9ms, total 30ms 02-04 12:40:33.665: D/dalvikvm(5637): GC_CONCURRENT freed 369K, 21% free 15658K/19644K, paused 2ms+2ms, total 18ms 02-04 12:40:33.725: D/dalvikvm(5730): GC_CONCURRENT freed 1166K, 23% free 15188K/19644K, paused 4ms+2ms, total 25ms 02-04 12:40:33.765: D/dalvikvm(5637): GC_CONCURRENT freed 430K, 20% free 15740K/19644K, paused 7ms+2ms, total 22ms 02-04 12:40:33.865: D/dalvikvm(5730): GC_CONCURRENT freed 325K, 23% free 15256K/19644K, paused 2ms+3ms, total 22ms 02-04 12:40:34.065: D/dalvikvm(5637): GC_CONCURRENT freed 1811K, 25% free 15934K/21040K, paused 3ms+2ms, total 29ms
  • 23. 23 Script result - Heap size and GC delays 0 0.2 0.4 0.6 0.8 1 1.2 0 20000 40000 60000 80000 100000 120000 140000 160000 Time in MSheap size in KB dalvikvm event timestamps current heap max heap
  • 24. 24 Script result - Heap size and GC delays 0 50 100 150 200 250 300 350 400 0 20000 40000 60000 80000 100000 120000 140000 160000 Time in MSheap size in KB dalvikvm event timestamps current heap max heap ui pause time total pause
  • 25. 25 Script result - Heap size and GC delays 0 50 100 150 200 250 300 350 400 0 20000 40000 60000 80000 100000 120000 140000 160000 Time in MSheap size in KB dalvikvm event timestamps current heap max heap ui pause time total pause webview start
  • 34. 34 Tips for managing GC Do How Avoid GC_FOR_ALLOC Load stuff in Splash Use Object Pools For large/heavy objects Avoid Complex Objects Use simpler Objects Perform Heap analysis Use MAT and DDMS Reduce memory use …
  • 35. 35 Summary • Application will crash –Collect and Analyze –Understand and Fix • Fixing the bug is half the fun
  • 36. 36 Back to the problem • JNI objects are a special case • Dalvik will finalize and Destroy • Timeouts will happen... And they Do!
  • 37. 37 Q&A • Questions? • Contact: Oren.barad@avg.com • We are hiring! • Come talk to us in the AVG booth
  • 38. 38 Links and resources • http://android-developers.blogspot.co.il/2011/03/memory- analysis-for-android.html • http://www.brpreiss.com/books/opus5/html/page424.html • http://java-is-the-new-c.blogspot.co.il/2013/07/tuning-and- benchmarking-java-7s-garbage.html • http://www.slideshare.net/muhammedshakirmisarwala/java- performance-monitoring-tuning • http://www.slideshare.net/VikasBalikai/gc-in-android • http://www.javacodegeeks.com/2012/01/practical-garbage- collection-part-1.html
  • 39. 39 Links and resources • https://android.googlesource.com/platform/dalvik/+/android- 4.3_r2/vm/alloc/MarkSweep.cpp • https://android.googlesource.com/platform/dalvik/+log/android- 4.4.2_r2/vm/alloc/MarkSweep.cpp • https://android.googlesource.com/platform/dalvik/+/gingerbread/vm/alloc/MarkSwe ep.c • https://android.googlesource.com/platform/dalvik/+/froyo- release/vm/alloc/MarkSweep.c