Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A small leak can crash a great app

A small leak can crash a great app

Memory Leaks :( As android engineers, this is a problem we face or are likely to face during the lifetime of our career. Debugging this kind of issue kind be quite tedious and frustrating. Without proper knowledge of what to look for, finding the root cause of such issues is really difficult. For this session, we are going to tackle memory leaks head on. We are going to go through the various causes of these memory leaks and how to handle each one. We are also going to take a look at various tools that you can use to pinpoint leaks so that you can easily fix them.

Michael Bukachi

August 09, 2019
Tweet

More Decks by Michael Bukachi

Other Decks in Programming

Transcript

  1. About me • Software Engineer (Android & Python) • Devops

    enthusiast • Dancer • Technical writer .droidconKe
  2. Enter Android Piece of logic runs longer than it's expected

    lifecycle .droidconKe IO operation goes rogue
  3. Causes .droidconKe • Storing lifecycle aware logic in application-scoped variables

    • Static variables • Inner classes • Callbacks/Listeners
  4. Causes .droidconKe • Unbound IO operations (Bad concurrency management) •

    Rogue threads • Using wrong scopes (Kotlin threads) • Forgetting unregister Broadcast Receivers • Non static inner classes
  5. What can we do? .droidconKe • Don't hold strong references

    to lifecycle objects. Use weak references if you really must. • Use structured concurrency, if you can [Kotlin :) ] • Use the right scopes (lifecycleScope, viewModelScope etc) • Remember to unregister you broadcast recievers • If you have logic which needs to survive the lifecycle, use the WorkManager • Use the application context when dealing with singletons