Android: “trying to use a recycled bitmap” error with temporary Bitmaps

前端 未结 1 1039
慢半拍i
慢半拍i 2021-01-03 23:46

My app can load quite large images. In an effort to be memory-conservative, I\'m attempting to use a temporary bitmap to load and another for the final image after transform

相关标签:
1条回答
  • 2021-01-04 00:08

    Straight from the Android documentation:

    Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made.

    It seems that the createBitmap functions have the potential to re-use the bitmap that you provided. If that is the case, then you shouldn't recycle the temporary bitmap since your final bitmap is using it. One thing you can do is

    if(tempBitmap != finalBitmap) {
       tempBitmap.recycle();
    }
    

    That should only recycle the tempBitmap when it isn't the same as the finalBitmap. At least that seems to be what the documentation is implying.

    0 讨论(0)
提交回复
热议问题