AndroidStudio MAT LeakCanary 内存分析之 LeakCanary
2024-08-24 13:30:30
现在我们换一种更清晰方便的方式:LeakCanary https://github.com/square/leakcanary
首先将LeakCanary绑在我们的app上
build.gradle
dependencies{
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
}
public class SunApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Global.mContext = SunApplication.this.getApplicationContext();
initializeLeakDetection();
} private void initializeLeakDetection() {
if (BuildConfig.DEBUG) {
LeakCanary.install(this);
}
}
}
Manifest 添加权限WRITE_EXTERNAL_STORAGE、不然会发生错误、如下代码
android 6.0以上另外获取权限、详情请见我的博文 Android 6.0 最简单的权限获取方法 RxPermition EasyPermition
<!--Required by Debug.startMethodTracing() -->
<!--LeakCanary need this Unable to resume activity
{com.rvitemtouch.sun.sundagger2application/com.squareup.leakcanary.internal.DisplayLeakActivity}:
java.lang.UnsupportedOperationException: Could not create leak directory
/storage/emulated//Download/leakcanary-com.rvitemtouch.sun.sundagger2application-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
安装好了、运行app、继续将之前写的(Android AndroidStudio MAT LeakCanary 内存分析之 AndroidStudio 内存泄漏分析 Memory Monitor)
Activity反复翻转屏幕、导致内存泄漏
出现内存泄漏提示
Leaks 会伴随我们的app一块install、那么打开leaks、等待一会
找到我们定位的泄漏 打开
就能看出详细的链式结构、上面写的很明白了、正如之前我们所料
是Memory..Activity的引用被Runnable占用了
最新文章
- nodejs pm2部署配置
- cygwin和mingw的区别
- C/C++ 记录时间
- 【dubbo】dubbo项目基本结构及provider构建
- Android控件颜色设置为透明
- IOS第八天(2:UITableViewController团购,点击底部,xib加载更多, 代理模式)
- easyui 进度条
- 定时组件quartz系列<;二>;quartz的原理
- UVa 10617 Again Palindromes / 记忆化搜索
- IOS 特定于设备的开发:使用加速器启动屏幕上的对象
- mybatis配置文件xxxx.xml中缺失返回类型的后果A query was run and no Result Maps were found
- python [1:3]
- 多线程(3)ThreadPool
- white-space:pre-wrap和word-break:break-all;
- WebClient图片下载
- 【Unity】项目工程源码
- UI5-学习篇-5-SAP创建OData服务-Structure
- Scala学习网址
- Oracle存储过程入参传入List集合的小例子
- 初始化 Flask 虚拟环境 命令