Fresco: OOM in 5.x ?????

Created on 3 Aug 2016  ·  5Comments  ·  Source: facebook/fresco

java.lang.OutOfMemoryError: Failed to allocate a 1638412 byte allocation with 987764 free bytes and 964KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:842)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:779)
at com.facebook.imagepipeline.memory.d.kC(BitmapPool.java:55)
at com.facebook.imagepipeline.memory.d.ku(BitmapPool.java:30)
at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:259)
at com.facebook.imagepipeline.g.a.a(ArtDecoder.java:137)
at com.facebook.imagepipeline.g.a.a(ArtDecoder.java:81)
at com.facebook.imagepipeline.decoder.a.a(ImageDecoder.java:128)
at com.facebook.imagepipeline.decoder.a.a(ImageDecoder.java:94)
at com.facebook.imagepipeline.producers.o$c.c(DecodeProducer.java:194)
at com.facebook.imagepipeline.producers.o$c.a(DecodeProducer.java:97)
at com.facebook.imagepipeline.producers.p.d(DecodeProducer.java:129)
at com.facebook.imagepipeline.producers.JobScheduler.NF(JobScheduler.java:207)
at com.facebook.imagepipeline.producers.JobScheduler.a(JobScheduler.java:27)
at com.facebook.imagepipeline.producers.ae.run(JobScheduler.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at com.facebook.imagepipeline.c.t.run(PriorityThreadFactory.java:43)
at java.lang.Thread.run(Thread.java:831)

needs-details

Most helpful comment

@Aloneter

Keep in mind that Fresco uses heap memory for caching images from Android 5.0. So you have to resize images before loading them. See Resizing section of the documentaion. Also, if you load PNG files, you'd better consider downsampling as well.

In my case, I encountered OOM, when I tried to load 18 PNG images, which is not so many when you use 3 columns gallery layout. Those PNG files were big, because they were screenshots of device. Because resizing only supports JPEG type, those big PNG files were loaded into memory as a whole, which result in OOM.

I resolved the issue by enabling downsampling.

ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setDownsampleEnabled(true) .build();
Fresco.initialize(this, config);

Hope my suggestion helps. :)

All 5 comments

How big are your images? How many images are you holding on to? Do you use animations?
You can try and resize your images or downsampling.
There are already many similar threads about OOMs.

@Aloneter

Keep in mind that Fresco uses heap memory for caching images from Android 5.0. So you have to resize images before loading them. See Resizing section of the documentaion. Also, if you load PNG files, you'd better consider downsampling as well.

In my case, I encountered OOM, when I tried to load 18 PNG images, which is not so many when you use 3 columns gallery layout. Those PNG files were big, because they were screenshots of device. Because resizing only supports JPEG type, those big PNG files were loaded into memory as a whole, which result in OOM.

I resolved the issue by enabling downsampling.

ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setDownsampleEnabled(true) .build();
Fresco.initialize(this, config);

Hope my suggestion helps. :)

@pungrue26

Still can't solve the problem!

The following is my configuration.

ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context);

    // 设置内存配置
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            getMaxCacheSize(context), // Max total size of elements in the cache
            256,                     // Max entries in the cache
            Integer.MAX_VALUE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);

    configBuilder.setBitmapMemoryCacheParamsSupplier(
            new Supplier<MemoryCacheParams>() {
                public MemoryCacheParams get() {
                    return bitmapCacheParams;
                }
            });

    // 设置缓存配置
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setBaseDirectoryPath(new File(FNConstants.Global.APP_CACHE))
            .setBaseDirectoryName(FNConstants.Global.APP_IMAGE_FRESCO_CACHE_DIR)
            .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE)
            .build();

    configBuilder.setMainDiskCacheConfig(diskCacheConfig);

    // 设置请求监听器配置
    Set<RequestListener> requestListeners = new HashSet<>();
    requestListeners.add(new RequestLoggingListener());

    configBuilder.setRequestListeners(requestListeners);

    configBuilder.setDownsampleEnabled(true);
    configBuilder.experiment().setWebpSupportEnabled(true);

    Fresco.initialize(context, configBuilder.build());

@pungrue26

This is the previous configuration.

// final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
// ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
// Integer.MAX_VALUE, // Max entries in the cache
// ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
// Integer.MAX_VALUE, // Max length of eviction queue
// Integer.MAX_VALUE); // Max cache entry size

Closing old issues.

Was this page helpful?
0 / 5 - 0 ratings