The Bitmap
memory problem in Android has led me to implement a custom loader and downloader class that will download an image from the web, store a local copy, and create a Bitmap
if requested to do so from the local copy. I'm keeping these in a list of SoftReference<T>
so that they are kept for a while, then garbage collected, at which point the class's finalize()
method is called:
protected void finalize() throws Throwable {
Log.w("IMAGEPACK", "Finalizing " + mBitmap);
if(mBitmap!=null&&!mBitmap.isRecycled()) mBitmap.recycle();
super.finalize();
}
Looking at LogCat I've determined that this piece of code is happening right before the crash. I've also stepped through the code and it's on this line that it fails.
I had a solution that used synchronized reference counting previously, and which seemed pretty reliable, but having had big problems with manually-written reference-counting before I wanted to avoid this. I may have to revert to it, but I would like to know WHY bitmap recycling is failing here.
I am currently testing on a Samsung Galaxy S on 2.3.3.