Sunday, July 15, 2012

Re: [android-developers] Jelly Bean Crash with Bitmap Recycle "Sorry, an error has occurred: bitmap is recycled"

Ah, yes, thanks Romain, that was it!  Cheers.

On Sunday, 15 July 2012 06:45:58 UTC+10, Romain Guy (Google) wrote:
Ah, this is an interesting bug that we ran into ourselves. createScaledBitmap() can return the *same* bitmap if the scaled copy would have the same dimensions as the original image. The proper way to do this is to write:

bitmap = Bitmap.createdScaledBitmap(oldBitmap, etc...);
if (bitmap != oldBitmap) oldBitmap.recycle();




On Fri, Jul 13, 2012 at 6:42 AM, Craigo wrote:
Hi Google,

My app that has been running for over 2 years without an update, finally broke with Jelly Bean.  The error: "Sorry, an error has occurred: bitmap is recycled".

The problem was with calling recycle on a bitmap:

Bitmap bitmapOld = bitmap;
bitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);
bitmapOld.recycle();

Note: I never referenced bitmapOld again.

The fix was easy, I just don't recycle any more.  However, it seems odd that this would have broken.  Maybe creating the scaled bitmap shares memory with the unscaled bitmap?

Anyway, hopefully this information is useful to someone.

Cheers, and keep up the excellent work!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Romain Guy
Android framework engineer
romainguy@android.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment