chrisbanes / Android-BitmapCache

Android-BitmapCache is a specialised cache, for use with Android Bitmap objects.
834 stars 224 forks source link

Removed bitmaps on LruCache is not checked if it is being used #41

Open ghost opened 10 years ago

ghost commented 10 years ago

In BitmapMemoryLruCache#getBitmapFromRemoved method, we judge if the bitmap is used by following: value != null && value.isBitmapValid() && value.isBitmapMutable() This is not enough and should be added following: && !value.isBeingDisplayed() && !value.isReferencedByCache()

This is because LruCache#entryRemoved is not called on the bitmap is no more used but called on the last method call of LruCache#get for the bitmap is in the distant past.

I met this issue when using ListView on ViewPager. When I scrolled ListView enough and changed page, bitmaps on another pages are not correct.

elroid commented 10 years ago

I second the need for "&& !value.isBeingDisplayed()". If you have CacheableImageViews that are always visible, and CacheableImageViews in a list view as well, the bitmap of the statically visible image will often get recycled incorrectly (and start showing one of the images from the list).