Bitmap Size Exceeds VM Budget Error On Android
Solution 1:
Bitmaps aren't compressed so they are stored in width * height * 4
bytes. It means that every image uses about 225 KB of memory. 100 images require about 22 MB of memory. The minimal heap size is 16 MB, but devices usually have 24+ MB heap. And this heap is used not only for data but also for activities, view and so on. That means you can't load 100 bitmaps of this size.
Solution 2:
As a rule of thumb you should only ever need to show what the user can actually see. Holding anything else (graphics) in memory is just icing on the cake. This is why devices with higher resolution screens will have larger heap sizes available.
For example, on a 320x480 screen, you would only need as a minimum, 320x480x4=614400 (600kb).
Taking this concept into mind, you need to consider whether you need to hold 100 Bitmap
s in memory. Is the user looking at 100 Bitmap
s at one time? In that case you can reduce the quality of the images without degrading the user experience (there are only so many pixels on the screen). Is the user scrolling through 100 Bitmap
s? Then dump and load images dynamically as appropriate (with a bit of caching for smoothness).
There is always a workaround.
Post a Comment for "Bitmap Size Exceeds VM Budget Error On Android"