位图和 Android 堆
我的应用程序使用一些带有 SurfaceView 的位图。对于经常调用的位图,我将它们存储为类字段,即当创建 SurfaceView 实例的扩展时,我有
bitmap_puppyicon = BitmapFactory.decodeResource(getResources(),R.drawable.puppy);
其中 bitmap_puppyicon 是我的扩展 SurfaceView 的类变量。我认为这意味着它在堆上。
对于使用一次或两次左右的位图,我在 onDraw() 方法中动态创建它们。
我检查了 DDMS 中的堆,觉得我可以将更多位图存储为类变量,而不是在 onDraw() 中创建它们。
令我惊讶的是,执行此操作后堆大小下降了几个百分点。我是否误解了什么?为什么存储的位图越多,堆就会变得越小?
My app uses some bitmaps with a SurfaceView. For bitmaps that a recalled often I stored them as class fields, i.e. when my extension of SurfaceView instance is created I have
bitmap_puppyicon = BitmapFactory.decodeResource(getResources(),R.drawable.puppy);
Where bitmap_puppyicon is a class variable of my extended SurfaceView. WHich means, I think, it is on the heap.
For bitmaps that are used once or twice or so, I created them on the fly in the onDraw() method.
I checked out the heap in DDMS and felt I could afford to store more bitmaps as class variables instead of creating them in onDraw().
To my surprise the heap size went down a few percentage points after doing this. Have I misunderstood something? Why would the heap get smaller with more bitmaps stored?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它在底层使用skia,并且堆不是位图所在的地方,在堆中您仅具有指向位图的链接
It use skia under the hood, and heap is not the place where bitmaps live, In the heap you have links to bitmaps only