Open
Conversation
added 2 commits
December 27, 2018 13:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
极客账号:18718572230
先看下输出:
{
"hash":566918239,
"size":24964,
"width":79,
"height":79,
"duplicatedCount":2,
"stack":[
,
]
}
实现思路:
1.通过haha库中 MemoryMappedFileBuffer 和 HprofParser 解析 hprof 文件,生成 Snapshot
2.snapshot 通过 findClass 查找 Bitmap ClassObj 对象
3.通过 snapshot 获取 app 和 default 的 Heap 对象,通过 classObj 搜集Bitmap 的 Instance List
4.遍历上面收集的List,存入一个key为 mBuffer hash 值,value 为 List 的Map中
5.Map中去除没有重复的元素(value size 为1 就是没有重复的)并创建数据结构
6.获取 Trace,这里感谢前面小哥们铺路,我两个方法都尝试了:
1.getNextInstanceToGcRoot 这个方法前有说返回null,需要调用 snapshot.computeDominators() 才会返回
2.通过使用LeakCanary的方式,调用 HeapAnalyzer.findLeakTrace 方式
两者输出的形式有点不一样,后面采用的是 LeakCannary 的方式,因为这个方式可以提供的信息更多一点(作业中我将输出的信息修改输出类全路径)
疑问和体会:
相关搜索资料比较少,可能我找的方向不太对,作业提供的信息是 Haha 库 和 perflib ,google下来的信息也比较少,直接啃源码比较难,后面查看了 LeakCanary 源码,加上有同学 pr 了,研究同学作业,最后慢慢才摸索出来。