Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于图片加载缓存 问题 #44

Open
huizai0613 opened this issue Nov 10, 2015 · 1 comment
Open

关于图片加载缓存 问题 #44

huizai0613 opened this issue Nov 10, 2015 · 1 comment

Comments

@huizai0613
Copy link

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

@kymjs
Copy link
Owner

kymjs commented Nov 20, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants