KJFrameForAndroid icon indicating copy to clipboard operation
KJFrameForAndroid copied to clipboard

关于图片加载缓存 问题

Open huizai0613 opened this issue 9 years ago • 1 comments

/** * @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

huizai0613 avatar Nov 10 '15 02:11 huizai0613

新版本已经改为系统的LruCache,原框架中的LruCache摘自API 17的源码。

kymjs avatar Nov 20 '15 09:11 kymjs