开发者

Efficient way to manage large array of bitmaps android

开发者 https://www.devze.com 2023-02-08 11:27 出处:网络
I have a question regarding the recommended/best practice for managing a large array of bitmaps. (It\'s a flipbook typ开发者_开发知识库e app where the user goes through and creates new pages...like a

I have a question regarding the recommended/best practice for managing a large array of bitmaps. (It's a flipbook typ开发者_开发知识库e app where the user goes through and creates new pages...like a virtual pile of sticky notes k?) Previously, I had an arraylist of objects that held bitmaps, (good performance) but I quickly ran into Out of Memory issues with the dalvik vm's heap limit.

I later tried storing the bitmaps not displayed on the screen to the sd card as cache and then grabbed them on demand, but I found this to be significantly slower on my phone than the previous method.

What is the best plan of attack for this problem?


Perhaps you could try a combination. Keep the bitmaps on sd card as cache and when bitmap "B" is loaded, you load bitmaps "A" and "C" into memory, where "A" and "C" are the bitmaps surrounding "B" in your app.


You should use both a strong referenced memory cache and a disk cache, see the Android Training class Displaying Bitmaps Efficiently, and in particular the Caching Bitmaps lesson.


One suggestion, If your bitmap is no longer usable or you want to remove it from memory. You should do,

bitmapObject.recycle();

It is the best efficient way to release bitmap memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号