mishti
mishti

Reputation: 193

My app freezes while using leak canary - why?

I am working on an Android TV app in which I have used Leak Canary Library but the problem is that when I use my after some time it shows me an error "Dumping Memory. App Freezes. Brrrr". I searched on Google do whatever suggested but still, I am getting the error.

In manifest, I have provided permission to write and read storage.

Code For Application Class:

     public class App extends Application {

private RefWatcher refWatcher;

public static RefWatcher getRefWatcher(Context context) {
    App application = (App) context.getApplicationContext();
    return application.refWatcher;
}

@Override
public void onCreate() {
    super.onCreate();
    refWatcher = LeakCanary.install(this);

}

And in my Activity and Fragments I have used RefWatcher in OnDestroy() . method.

i.e.

        @Override
protected void onDestroy() {

    if (timer != null) {
        timer.cancel();
        timer = null;
    }
    if (handler != null)
        handler.removeCallbacks(Update);
    super.onDestroy();


    RefWatcher refWatcher = App.getRefWatcher(this);
    refWatcher.watch(this);
}

But still I am getting Dumping Memory error. Please help.

Upvotes: 1

Views: 1483

Answers (3)

Emil S.
Emil S.

Reputation: 432

LeakCanary, as you probably know, is intended to detect memory leaks in your application. When it shows the "Dumping Memory. App Freezes. Brrrr"-Message it isn't because you've setup LeakCanary wrong, but because LeakCanary is working as intended and has detected a leak.

The app freezes because LeakCanary has to record the current status of every thread in the application and the memory to then give you a report on the leak that it detected.

So you seeing this message means your app has memory leaks that need fixing. Check the report you get for that leak in the "Leaks"-App, your logcat-output or by clicking the notification that pops up. In there you should find details on what has leaked.

Upvotes: 1

SebRut
SebRut

Reputation: 604

As the message suggests LeakCanary freezes the app to dump its current memory for analysis. This is normal behaviour and intended. You should get a notification with more details regarding potential detected leaks. You can also check the "Leaks"-App or the logcat output of your app for details.

Upvotes: 1

Dmytro Ivanov
Dmytro Ivanov

Reputation: 1310

LeakCanary using different type of dependecies.

debugImplementation "com.squareup.leakcanary:leakcanary-android:1.6.2"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:1.6.2"
debugImplementation "com.squareup.leakcanary:leakcanary-support-fragment:1.6.2"

If your app in release stage, lib will never appear "Dumping Memory. App Freezes. Brrrr".

Here is my example of init LeakCanary. Inside Application() class, in method onCreate(), im calling

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

Upvotes: -1

Related Questions