java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android

android, bitmap, memory, memory-leaks, out-of-memory

Solution

It sounds like you have a memory leak. The problem isn't handling many images, it's that your images aren't getting deallocated when your activity is destroyed.

It's difficult to say why this is without looking at your code. However, this article has some tips that might help:

http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html

In particular, using static variables is likely to make things worse, not better. You might need to add code that removes callbacks when your application redraws -- but again, there's not enough information here to say for sure.

Problem

I developed an application that uses lots of images on Android. The app runs once, fills the information on the screen (`Layouts`, `Listviews`, `Textviews`, `ImageViews`, etc) and user reads the information. There is no animation, no special effects or anything that can fill the memory. Sometimes the drawables can change. Some are android resources and some are files saved in a folder in the SDCARD. Then the user quits (the `onDestroy` method is executed and app stays in memory by the VM ) and then at some point the user enters again. Each time the user enters to the app, I can see the memory growing more and more until user gets the `java.lang.OutOfMemoryError`. So what is the best/correct way to handle many images? Should I put them in static methods so they are not loaded all the time? Do I have to clean the layout or the images used in the layout in a special way?

Original source

Related problems