Monday, October 25, 2010

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap

Recently our two applications on Android Market kept reporting error “java.lang.RuntimeException: Canvas: trying to use a recycled bitmap…”. If you look at the stack trace, there is no trace of our code. Below is one of the stack trace:

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap
at android.widget.ImageView.onDraw(
at android.view.View.draw(
at android.view.ViewRoot.draw(
at android.view.ViewRoot.performTraversals(
at android.view.ViewRoot.handleMessage(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(
at dalvik.system.NativeStart.main(Native Method)


After searching around the Internet, I found some clues. It has something to do with the call of bitmap.recycle(). Some people suggest to remove all the calls to bitmap.recycle() and let the garbage collector to do the job. So I tried this solution and updated the Packing List application. I will give it a day or two to see if it settles the issue.


  1. first you should not remove bitmap.recycle() function, removing it may cause Out Of Memory Error. "trying to use a recycled bitmap" exception occurs when you try to recycle a already recycled bitmap.

    Better you can use the below solution to fix the issue.

    BitmapDrawable bitmapDrawable = ((BitmapDrawable) profileWallpaper.getDrawable());

    note: profileWallpaper is your bitmap imageView

    if (null != bitmapDrawable && bitmapDrawable.getBitmap().isRecycled()) {

    } else {

    log("bitmap is already recycled");

    bitmapDrawable = null;

  2. but why does this problem occurs