I got a list view in which im display images, these images are loaded and cached properly. When I look at the list and load new items, I want to recycle the least recently used for saving in memory. I have successfully implemented LRU Map and im call recycle on bitmaps that are not visible on the screen. Here is the piece of code:
imageView is a ViewGroup
public void recycleImage(int res) { if (imageView != null) { imageView.setBackgroundDrawable(null); if (res > 0) imageView.setBackgroundResource(res); } if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); Log.i(TAG, "Bitmap recycled"); } }
These values ββare stored in the getView method of the adapter. The problem is that when I process the images, I see how those that are visible on the screen are also lost (note that only those that I know come out of the screen).
Does anyone have an idea on why I am losing the images currently displayed when I processed the bitmaps of others in the list?
Here I refer to the downloaded bitmap or load it.
if (mImageMap.containsKey(url)) { ImageCacheModel cache = mImageMap.get(url); return cache.getBitmap(); } else if (cacheManager.isUrlCached(url)) { mImageMap.put(url, new ImageCacheModel(imageView, cacheManager.getCachedBitmapOrNull(url, 2))); ImageCacheModel cache = mImageMap.get(url); return cache.getBitmap(); } else { cacheManager.addUrlToQueue(url, this, true); }
source share