Android: OutofMemoryError: bitmap size exceeds VM budget with no reason I can see

I think there’s nothing special in your case. There’s just not enough memory. You can’t have several 600×800 bitmaps in memory, they consume too much memory. You should save them to SD and load to memory on demand. I think that’s exactly what you do.

One thing you should be aware of: DDMS displays java heap memory consumption. But there’s also native memory that is not displayed in DDMS. And bitmaps as far as I understand are created in native memory. So DDMS is just a bad tool to track these memory issues. You just need to be sure that you free your memory, that images are collected by Garbage Collector after you don’t need them any more.

Garbage Collector works on it’s own schedule. That’s why you should call Bitmap.recycle() method on bitmaps that you don’t need any more. This method frees exactly the native memory that you run out of. This way you don’t depend on GC and you can free largest piece of memory as soon as possible.

First of all you should ensure that you don’t leak bitmaps.

Here’s a nice post on memory allocations, it can help you to dig deeper

Leave a Comment