在一个静态变量存储一个位图资源 [英] Storing a Bitmap resource in a static variable

查看:167
本文介绍了在一个静态变量存储一个位图资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示一个小位图的说法,这是用在很多地方在我的应用程序(尤其是列表视图)。我使用的是创建视图的一个实例 BitmapFactory.de codeResource(资源ID)每次当前加载此位图。我意识到,我可以通过加载位图一旦进入一个静态变量(这样认为的所有实例重复使用它),提高性能,并且确实节省按次如约2-4毫秒。我的问题,并以这种方式使用一个静态变量引起的Andr​​oid任何类型的内存泄漏?我很担心,因为我还没有发现使用一个静态变量来存储这样的位图的其他例子。

I have a view which displays a small bitmap, and this is used in many places in my application (especially list views). I'm currently loading this bitmap each time an instance of that view is created using BitmapFactory.decodeResource(resource, id). I realized that I can improve performance by loading that bitmap once into a static variable (so that all instances of the view reuse it) and that did indeed save about 2-4 ms per view instance. My question, does using a static variable in this way cause any type of memory leak in Android? I'm worried because I haven't found any other example that uses a static variable to store a bitmap like this.

跟进的问题: 如何保持位图在内存

推荐答案

保持的位图对象,以免静电会引起潜在的内存泄漏,请参阅官方文件 http://android-developers.blogspot.co.uk /2009/01/avoiding-memory-leaks.html

Keeping bitmap objects as static may cause potential memory leaks, see official documents at http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

这篇关于在一个静态变量存储一个位图资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆