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

OOM if scroll but works when not scrolled (logcat) #15

Open
edindubai opened this issue Jan 6, 2017 · 1 comment
Open

OOM if scroll but works when not scrolled (logcat) #15

edindubai opened this issue Jan 6, 2017 · 1 comment

Comments

@edindubai
Copy link

https://drive.google.com/file/d/0B-GeS9MutjJONFJFYTV5cTNON2c/view

@SuperTxy
Copy link

解决OOM问题,自测已没问题,初始化Fresco时,要添加如下内容:
private void initFresco() {
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig
.newBuilder(getApplicationContext())
.setDownsampleEnabled(true)
.setBitmapMemoryCacheParamsSupplier(new LollipopBitmapMemoryCacheParamsSupplier(activityManager))
.build();

    Fresco.initialize(getApplicationContext(), imagePipelineConfig);
}

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);

// 不确定用哪个
// return new MemoryCacheParams(getMaxCacheSize(), 1, 1, 1, 1);
} 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;
        }
    }
}

}

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