MAT下载地址
Eclipse Memory Analyzer 的使用教程最实用
[LeakCanary原理解析]https://www.jianshu.com/p/261e70f3083f
1.打开androidstudio 的 profiler

2.点击profiler上的加号

3.当怀疑某个activity或者页面出现内存泄漏,频繁操作,创建该页面,观察内存变化,

4.当内存不断增加,点击那个垃圾箱,进行gc

5.点击向下的箭头,dump出堆信息

6.在sdk/platform-tools下使用如下命令,转换dump文件格式
hprof-conv dump.hprof converted-dump.hprof

7.用mat打开转换过的dump文件

查看方式一:
8.点击直方图histogram,可以在第一行ClassName下搜索你要查看的类

9.对着Activity右键 -> List objects -> with incoming references查看具体Activity实例

10.可以对着任意一个Activity的实例右键 -> Path to GC Roots -> exclude weak references,查看引起泄露的引用类

查看方式二:通过包找到对应的类,对象情况。


网友评论