recycle bitmap ice cream sandwich force close

1k Views Asked by At

In my ondestroy method, I recycle all the bitmaps I've used to free up memory and keep the app from crashing during screen rotations. This has proven to be the right thing to do for all apis until ice cream sandwich (android 4.0). now, when I rotate on ICS I get a force close and the logcat is not useful. I cannot trace it back to my code, but when I remove the bitmap recycling, it works great for ICS. Any ideas on this?

1

There are 1 best solutions below

5
On

Are you recycling bitmaps that were retrieved from the resources? It sounds like the OS keeps a reference to the Bitmap and uses it for future calls to the same resource. In that case, when the screen rotates, it will try to use the same Bitmap that you just recycled. This will result in a force close.

You may not need to recycle the bitmaps manually at all. It is a very dangerous call, especially on Bitmaps loaded from the resources.