美文网首页
android内存分析

android内存分析

作者: waiwaaa | 来源:发表于2018-03-27 17:00 被阅读0次

界面说明

打开Android Studio看下它的界面,在最底下可以找到 Android Monitor标签,如图


image.png

Memory五个按钮的作用从左到有分别是:

  • (Enabled)暂停内存监视器的工作
  • (Initial GC)启动垃圾回收,一般在Dump Java Heap之前用来清楚无用对象。
  • (Dump Java Heap)生成一份当前内存使用情况的日志
  • (Start Allocation Tracking)记录一段区间内各个线程各个方法的内存分配情况
  • (Memory monitor help)查看帮助文档

步骤:

1.先“启动垃圾回收”,可以多点几次
2.生成一份当前内存使用情况的日志
3.按包排序,查找可能泄漏的类


image.png

4.导出标准格式的hprof文件


image.png
5.MAT打开hprof文件,并找到出问题的类
image.png
6.右击搜索出来的类名,选择Merge Shortest Paths to GC Roots的exclude all phantom/weak/soft etc. references,来到这一步,就可以看到内存泄漏的原因,我们就需要根据内存泄漏的信息集合我们的代码去分析原因。

MAT下载地址
hprof文件转标准格式hprof-conv xxx.hprof txx.hprof

相关文章

网友评论

      本文标题:android内存分析

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