使用 Memory Analyzer ( MAT ) 工具分析內存 ( hprof 文件轉換 | MAT 工具下載 | MAT 工具使用 )
jdk下載
MAT下載地址
Eclipse Memory Analyzer 的使用教程最實用
[LeakCanary原理解析]http://www.lxweimin.com/p/261e70f3083f
1.打開androidstudio 的 profiler
image.png
2.點擊profiler上的加號
image.png
3.當懷疑某個activity或者頁面出現內存泄漏,頻繁操作,創建該頁面,觀察內存變化,
image.png
4.當內存不斷增加,點擊那個垃圾箱,進行gc
image.png
5.點擊向下的箭頭,dump出堆信息
image.png
6.在sdk/platform-tools下使用如下命令,轉換dump文件格式
hprof-conv dump.hprof converted-dump.hprof
image.png
7.用mat打開轉換過的dump文件
image.png
查看方式一:
8.點擊直方圖histogram,可以在第一行ClassName下搜索你要查看的類
image.png
9.對著Activity右鍵 -> List objects -> with incoming references查看具體Activity實例
image.png
10.可以對著任意一個Activity的實例右鍵 -> Path to GC Roots -> exclude weak references,查看引起泄露的引用類
image.png
查看方式二:通過包找到對應的類,對象情況。
image.png
image.png