简体   繁体   中英

Storing a Bitmap resource in a static variable

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.

Follow up question: How to keep a Bitmap in memory

将位图对象保持为静态可能会导致潜在的内存泄漏,请参阅http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html上的官方文档。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM