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

Memory Leaks on M (Square NYC 2016)

Memory Leaks on M (Square NYC 2016)

LeakCanary is a handy tool in any Android developer’s toolbox. However, with the advent of Marshmallow, LeakCanary started to throw its own OutOfMemory errors!

In this lightning talk, we'll dig into why this happens and how we’re fixing it so that you all can go back to writing awesome apps with increased confidence.

Presented at https://www.showclix.com/event/square-new-york-presents

Video: https://www.youtube.com/watch?v=r6qdW4mbfmA

John Rodriguez

March 10, 2016
Tweet

More Decks by John Rodriguez

Other Decks in Programming

Transcript

  1. public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
 
 public static void

    install(Context context) {
 Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
 OomExceptionHandler oomHandler = new OomExceptionHandler(defaultHandler, context);
 Thread.setDefaultUncaughtExceptionHandler(oomHandler);
 }
 }
  2. public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
 
 public static void

    install(Context context) {
 Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
 OomExceptionHandler oomHandler = new OomExceptionHandler(defaultHandler, context);
 Thread.setDefaultUncaughtExceptionHandler(oomHandler);
 }
 }
  3. public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
 
 public static void

    install(Context context) {
 Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
 OomExceptionHandler oomHandler = new OomExceptionHandler(defaultHandler, context);
 Thread.setDefaultUncaughtExceptionHandler(oomHandler);
 }
 
 @Override public void uncaughtException(Thread thread, Throwable ex) {
 if (containsOom(ex)) {
 File heapDumpFile = new File(context.getFilesDir(), FILENAME);
 try {
 Debug.dumpHprofData(heapDumpFile.getAbsolutePath());
 } catch (Throwable ignored) {
 }
 }
 defaultHandler.uncaughtException(thread, ex);
 }
 }
  4. # GC Roots = 251,478 # Unique Roots = 50,016

    top uniques: int[65536]: 26143 java.lang.Class[7581]: 26143 int[32062]: 15117 java.lang.Class[3409]: 15117 int[29760]: 9176 java.lang.Class[3127]: 9176 com.android.internal.R$styleable: 2271 android.R$styleable: 2072 java.lang.Class[687]: 1425
  5. # GC Roots = 251,478 # Unique Roots = 50,016

    top uniques: int[65536]: 26143 java.lang.Class[7581]: 26143 int[32062]: 15117 java.lang.Class[3409]: 15117 int[29760]: 9176 java.lang.Class[3127]: 9176 com.android.internal.R$styleable: 2271 android.R$styleable: 2072 java.lang.Class[687]: 1425