I require displaying many images in my application. These being jpgs and pngs and i'm loading them inside ImageViews like so:
tile.setImageResource(R.drawable.tile_highlight);
I am currently having OutOfMemory problems (java.lang.OutOfMemoryError: bitmap size exceeds VM budget
)
I've searched and found some other posts, they all suggest that you should recycle the bitmap of an ImageView manually, like so: ((BitmapDrawable)imageView.getDrawable()).getBitmap().recycle();
which will dump it from memory.
BUT in my case, being that i'm not using setBitmap()
to load the images onto the ImageView objects, when i try and run the above code, it returns NullPointerException
, more precisely, the method getBitmap()
returns null, there is no bitmap ?!?!
Do i need to go back in my code and change the way i load all the images in the ImageViews, and then try with the recycle()
method? Or how can i free up the memory so it doesn't crash anymore?
EDIT
I've tried something like so: imageView.setImageResource(-1);
in hopes it will remove the image from memory and replace it with ... null or something, but it seems it doesn't help the cause.