完成作业及Demo,实现内存中重复Bitmap的检测#14
Open
freshxu wants to merge 1 commit intoAndroidAdvanceWithGeektime:masterfrom
Open
完成作业及Demo,实现内存中重复Bitmap的检测#14freshxu wants to merge 1 commit intoAndroidAdvanceWithGeektime:masterfrom
freshxu wants to merge 1 commit intoAndroidAdvanceWithGeektime:masterfrom
Conversation
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.
参考了下面各位大神的代码,写出来后觉的思路挺简单的,但是如果不看别人的根本不会。。。
步骤如下:
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、打印信息
继续学习吧,还差的很远