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

怎样设置加载最大缓存 #738

Closed
GCZeng opened this issue Nov 9, 2015 · 2 comments
Closed

怎样设置加载最大缓存 #738

GCZeng opened this issue Nov 9, 2015 · 2 comments
Assignees

Comments

@GCZeng
Copy link

GCZeng commented Nov 9, 2015

我现在用fresco加载一个列表,列表每一个item都是一张图片,加载到大概10页面左右,就使用了200M左右的内存,这个内存可以通过回收控制吗,怎样优化?

@tianlang
Copy link

tianlang commented Nov 9, 2015

你测试机是5.0以上系统吧,5.0以上系统 需要配置一下,不能无限制使用内存缓存

我是这样配置的:

public class LollipopBitmapMemoryCacheParamsSupplier implements Supplier {

private ActivityManager activityManager;

public LollipopBitmapMemoryCacheParamsSupplier(ActivityManager activityManager) {
    this.activityManager = activityManager;
}

@Override
public MemoryCacheParams get() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new MemoryCacheParams(getMaxCacheSize(), 56, Integer.MAX_VALUE,
                Integer.MAX_VALUE,
                Integer.MAX_VALUE);
    } else {
        return new MemoryCacheParams(
                getMaxCacheSize(),
                256,
                Integer.MAX_VALUE,
                Integer.MAX_VALUE,
                Integer.MAX_VALUE);
    }
}

private int getMaxCacheSize() {
    final int maxMemory = Math.min(activityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE);

    if (maxMemory < 32 * ByteConstants.MB) {
        return 4 * ByteConstants.MB;
    } else if (maxMemory < 64 * ByteConstants.MB) {
        return 6 * ByteConstants.MB;
    } else {
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD) {
            return 8 * ByteConstants.MB;
        } else {
            return maxMemory / 4;
        }
    }
}

}

@anAngryAnt
Copy link

@tianlang 可以问一下你为什么要这样配置么? MemoryCacheParams的cacheEntries为什么要设置56和256?

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

4 participants