LeakCanary memory leak detection tools

AndroidStudio project can be built-in memory leak detection tools, but I'm not used to the feeling. . . Found a better detection tool called: LeakCanary, use is also very simple, following began:


The first step, adding a dependency:

debugCompile   'com.squareup.leakcanary:leakcanary-android:1.5'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    testCompile    'com.squareup.leakcanary:leakcanary-android-no-op:1.5'

The second step, add the following code inside MyApplication

public class MyApp extends Application {

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

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

    }


}

(Do not forget the statement manifests inside application name)

Then you can use directly, using the results as follows:



(Forgive the test machine is no network can not share, I was too lazy to use their mobile phones to test ... So this happens, I will not Screenshot ,,,,,,,)

When I switch back and forth two Aty which has a non-static inner classes so cause internal leakage, that we point inside look into MainActivity


Buddies. . . It also takes too much of it. . . .

Can be seen in mLinstener to hold a memory leak because MainActivity references

It can be said to be very intuitive


Published 124 original articles · won praise 141 · views 160 000 +

Guess you like

Origin blog.csdn.net/weixin_36838630/article/details/79627817