Como configurar y usar LeakCanary para detectar errores de tipo OutOfMemoryError en nuestra aplicación Android.
-------------------------------------
Configuración
-------------------------------------
1. Agregar las dependencias al gradle del app.
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' // or 1.4-beta1
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' // or 1.4-beta1
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' // or 1.4-beta1
}
2. Agregar los wacther a la clase Application del App.
// Variable watcher
private RefWatcher refWatcher;
// En el método onCreated agregar la instalación del LeakCanary
refWatcher = LeakCanary.install(this);
// Agregrar el método estático para obtener el watcher
public static RefWatcher getRefWatcher(Context context) {
MyApplication application = (MyApplication) context.getApplicationContext();
return application.refWatcher;
}
3. Utilizar el watcher en la clase sospechosa
RefWatcher refWatcher = MyApplication.getRefWatcher(context);
refWatcher.watch(/* su componente a inspeccionar*/);
More information:
http://www.yaircarreno.com/2016/03/le...