KJFrameForAndroid
KJFrameForAndroid copied to clipboard
关于图片加载缓存 问题
/** * @param maxSize * the maximum size of the cache before returning. May be -1 to * evict even 0-sized elements. */ private void trimToSize(int maxSize) { while (true) { K key; V value; synchronized (this) { if (size < 0 || (map.isEmpty() && size != 0)) { throw new IllegalStateException(getClass().getName() + ".sizeOf() is reporting inconsistent results!"); }
if (size <= maxSize) {
break;
}
//This line Map.Entry<K, V> toEvict = null; for (Map.Entry<K, V> entry : map.entrySet()) { toEvict = entry; } //This line if (toEvict == null) { break; }
key = toEvict.getKey();
value = toEvict.getValue();
map.remove(key);
size -= safeSizeOf(key, value);
evictionCount++;
}
entryRemoved(true, key, value, null);
}
}
上面的代码 是不是 有问题 啊 这样的话 每次 取出 的都是 最后 put 的bitmap
新版本已经改为系统的LruCache,原框架中的LruCache摘自API 17的源码。