Search code examples
androidmemory-leaksleakcanary

Is my leakcanary working? How to know?


I believe to have successfully installed LeakCanary.

I added the debug, release, and test dependencies to the build.gradle file.

I added the necessary files to my Application Class. Imported as necessary. Confirmed the application class is properly added to manifest. Does my application class need to be explicitly called?

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"

I run my app on the emulator and don't see anything different. I monitor the Android Monitor and don't see any difference. How do I know if it's all working? I've shared my Application class.

import android.app.Application;
import android.content.res.Configuration;
import com.squareup.leakcanary.LeakCanary;

public class MyApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    if (LeakCanary.isInAnalyzerProcess(this)) {
        return;
    }
    LeakCanary.install(this);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

@Override
public void onLowMemory() {
    super.onLowMemory();
}

}


Solution

  • Does my application class need to be explicitly called?

    No.

    How do I know if it's all working?

    Leak something intentionally. For example, assign your launcher activity instance to a static field.