Skip to content

Conversation

@freshxu
Copy link

@freshxu freshxu commented Jul 29, 2022

参考了下面各位大神的代码,写出来后觉的思路挺简单的,但是如果不看别人的根本不会。。。

步骤如下:

1、Debug.dumpHprofData 生成当时App的内存快照,Hprof 文件
2、使用 HaHa 库对 Hprof 文件进行解析,snapshot.findClass(“android.graphics.Bitmap”) 可以拿到 内存中 Bitmap 的 ClassObj
3、classObj 的 Heap 有四种,app、default、image、zygote(Android Studio Profile 里也可以看到这四种),我们图片主要在 app 中,因此拿到 app 的 Heap 就行
4、通过 ClassObj 可以拿到 app heap 中所有的 Bitmap 实例 Instance
5、通过 Haha 库可以拿到实例中的各种属性 "mBuffer"、“mWidth”, “mHeight”,然后通过比较不同 instance mBuffer 的 hashCode 来确定是否是相同图片
6、通过 Instance 的 getNextInstanceToGcRoot 来拿到堆栈信息(发现没法直接定位到具体的位置)
7、打印信息

继续学习吧,还差的很远

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant