There is a nice callback in the cache called entryRemoved which gives you the item after it’s removed, and you would think here is the perfect time to call Bitmap.recycle(), but donot do this. The reason is that there is no guarantee that the Bitmap isn’t being referenced by a View, and you can’t recycle a Bitmap being used.
Bitmap.recycle()
本文探讨了在缓存回调机制中Bitmap回收的最佳实践。文章指出,在缓存的entryRemoved回调中直接调用Bitmap.recycle()存在风险,因为无法确保Bitmap未被View引用。若在使用中尝试回收Bitmap,可能导致应用崩溃。
There is a nice callback in the cache called entryRemoved which gives you the item after it’s removed, and you would think here is the perfect time to call Bitmap.recycle(), but donot do this. The reason is that there is no guarantee that the Bitmap isn’t being referenced by a View, and you can’t recycle a Bitmap being used.

被折叠的 条评论
为什么被折叠?



