您的位置:首页 > 移动开发 > Android开发

Android内存泄露分析工具LeakCanary

2017-04-10 16:34 399 查看
转载:http://blog.csdn.net/android_zhengyongbo/article/details/69951010

添加依赖

compile 'com.squareup.leakcanary:leakcanary-android:1.5'


在Application中初始化添加下面代码

正式发布的时候注销下面代码

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);


ok这样已经可以用了,在安装你的App的时候桌面还会出现一个Leaks的App,里面有内存泄露的日志,可以查看并且解决问题。

如果有static变量造成的泄露可以在onDestory方法中设置为null

例如:
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if(mStatic!=null){
mStatic=null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: