首先用Android studio 生成hprof文件比如文件名叫xxx.hprof然后用hprof-conv xxx.hprof memory-converted.hprof因为MAT只支持java版的hprofas生成的hprof只能android版本的hprof直接导入MAT会报错。然后通过mat打开这个memory-converted.hprof然后open a Heap Dump- Leak Suspects Report通过分析可以看到Bitmap 占用的内存比较多 点开detail-Suspect Objects by Classfirst 10 of 304objects 点开对象列表然后找最大的对象右键Path to gc Roots-Exclude Weak References 然后就可以看到对象的引用了。我做了一个自动转hprof的脚本只要把这个做成app就可以把xxx.hprof 拖到这个app上就能生成convert的hprof了on open droppedItems repeat with oneItem in droppedItems set inputPath to POSIX path of oneItem -- 输出到原文件同目录文件名自动加 -converted do shell script input_file quoted form of inputPath dir$(dirname \$input_file\) base$(basename \$input_file\ .hprof) output_file\$dir/${base}-converted.hprof\ /opt/homebrew/bin/hprof-conv \$input_file\ \$output_file\ end repeat display dialog 转换完成 buttons {确定} default button 确定 end open然后可以通过打开Top Components-点开内存最大的比如system class loader (80%)-Top Consumer-Biggest Objects 根据Retained Heap 排序找大的对象进行分析
如何用MAT(Eclipse Memory Analyzer)
首先用Android studio 生成hprof文件比如文件名叫xxx.hprof然后用hprof-conv xxx.hprof memory-converted.hprof因为MAT只支持java版的hprofas生成的hprof只能android版本的hprof直接导入MAT会报错。然后通过mat打开这个memory-converted.hprof然后open a Heap Dump- Leak Suspects Report通过分析可以看到Bitmap 占用的内存比较多 点开detail-Suspect Objects by Classfirst 10 of 304objects 点开对象列表然后找最大的对象右键Path to gc Roots-Exclude Weak References 然后就可以看到对象的引用了。我做了一个自动转hprof的脚本只要把这个做成app就可以把xxx.hprof 拖到这个app上就能生成convert的hprof了on open droppedItems repeat with oneItem in droppedItems set inputPath to POSIX path of oneItem -- 输出到原文件同目录文件名自动加 -converted do shell script input_file quoted form of inputPath dir$(dirname \$input_file\) base$(basename \$input_file\ .hprof) output_file\$dir/${base}-converted.hprof\ /opt/homebrew/bin/hprof-conv \$input_file\ \$output_file\ end repeat display dialog 转换完成 buttons {确定} default button 确定 end open然后可以通过打开Top Components-点开内存最大的比如system class loader (80%)-Top Consumer-Biggest Objects 根据Retained Heap 排序找大的对象进行分析