美文网首页
内存泄露检测类库—LeakCanary

内存泄露检测类库—LeakCanary

作者: 青禾tester | 来源:发表于2017-04-28 09:57 被阅读0次

LeakCanary是Square公司推出的一个开源类库。

引入:可由Android开发,将该库接入工程中

作用:可以检测内存泄露

使用debug包,当出现内存泄露时

(1)在通知栏会收到一条leak通知;点开通知,显示一个leak trace 报告。

(2)桌面也有个leaks入口,点开查看trace

通知栏:

桌面入口+页面展示:

leak报告(可分享出去,分享到QQ/微信提示文字限制,可先分享到短信—再复制到微信):

GC ROOT static Docker.container

references Box.hiddenCat

leaks Cat instance

项目地址:

A memory leak detection library for Android and Java.

https://github.com/square/leakcanary

In your build.gradle:

dependencies {

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'

releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

}

In your Application class:

public class ExampleApplication extends Application {

@Override public void onCreate() {

super.onCreate();

if (LeakCanary.isInAnalyzerProcess(this)) {

// This process is dedicated to LeakCanary for heap analysis.

// You should not init your app in this process.

return;

}

LeakCanary.install(this);

// Normal app init code...

}

}

You're good to go! LeakCanary will automatically show a notification when an activity memory leak is detected in your debug build.

相关文章

网友评论

      本文标题:内存泄露检测类库—LeakCanary

      本文链接:https://www.haomeiwen.com/subject/jasozttx.html