位图和 Android 堆

发布于 2025-01-01 09:19:17 字数 423 浏览 6 评论 0原文

我的应用程序使用一些带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静水深流 2025-01-08 09:19:17

它在底层使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文