Fresco: Exception when prefetch

Created on 11 Jan 2016  ·  9Comments  ·  Source: facebook/fresco

Pool hard cap violation? Hard cap = 1048576 Used size = 1048576 Free size = 0 Request size = 16384
com.facebook.imagepipeline.memory.BasePool$PoolSizeViolationException: Pool hard cap violation? Hard cap = 1048576 Used size = 1048576 Free size = 0 Request size = 16384
at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:240)
at com.facebook.imagepipeline.memory.PooledByteStreams.copy(PooledByteStreams.java:52)
at com.facebook.imagepipeline.cache.BufferedDiskCache$6.write(BufferedDiskCache.java:333)
at com.facebook.cache.disk.DefaultDiskStorage.updateResource(DefaultDiskStorage.java:178)
at com.facebook.cache.disk.DiskStorageCache.insert(DiskStorageCache.java:289)
at com.facebook.imagepipeline.cache.BufferedDiskCache.writeToDiskCache(BufferedDiskCache.java:329)
at com.facebook.imagepipeline.cache.BufferedDiskCache.access$500(BufferedDiskCache.java:38)
at com.facebook.imagepipeline.cache.BufferedDiskCache$3.run(BufferedDiskCache.java:214)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)

needs-details

Most helpful comment

@michalgr You are right Thank you very much
below code work fine wor me hope this will help others:
MaxRequestPerTime = 64
SparseIntArray defaultBuckets = new SparseIntArray();
defaultBuckets.put(16 * ByteConstants.KB, MaxRequestPerTime);
PoolParams smallByteArrayPoolParams = new PoolParams(
16 * ByteConstants.KB * MaxRequestPerTime,
2 * ByteConstants.MB,
defaultBuckets);
PoolFactory factory = new PoolFactory(
PoolConfig.newBuilder()
. setSmallByteArrayPoolParams(smallByteArrayPoolParams)
.build());
ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(context,okHttpClient)
.setMainDiskCacheConfig(diskCacheConfig)
.setDownsampleEnabled(true)
.setPoolFactory(factory)
.build();

All 9 comments

Pool hard cap violation? Hard cap = 1048576 Used size = 1048576 Free size = 0 Request size = 16384
@tyronen how can i fix this issue? Thank you for any help! Best Wishes!

Hi. Do you set up any custom configuration ?

no,My config is very common , no any custom configuration 。
I use OkHttps.

@michalgr this happen random but very ofen. I suppose you shoul check the code where the log print.
Hope this can fix in next version.

Checking the place where the exception was throws won't help us that much. We need to understand why the pool is saturated, not where it was observed this particular time.

Do you know by any chance how many parallel requests are there going on in OkHttp ? If there are too many of them then response handlers will consume too many byte arrays from the pool. I'll suggest trying limiting number of parallel requests or increasing size of the pool. Anyway, you'll need a knowledge of what is going on in your app to decide which way to go.

Reducing number of parallel fetches might be done by configuring your OkHttpClient with appropriate Dispatcher (http://square.github.io/okhttp/3.x/okhttp/okhttp3/Dispatcher.html#Dispatcher-java.util.concurrent.ExecutorService-).

Increasing number of byte arrays in the pool is a bit more complex. When configuring pipeline provide configuration with custom pool factory (http://frescolib.org/docs/configure-image-pipeline.html). Creating PoolFactory that allows for more byte arrays in the pool would look like this:

    SparseIntArray defaultBuckets = new SparseIntArray();
    defaultBuckets.put(16 * ByteConstants.KB, NUMBER_OF_PARALLEL_NETWORK_FETCHES);
    PoolParams smallByteArrayPoolParams = PoolParams(
        16 * ByteConstants.KB * NUMBER_OF_PARALLEL_NETWORK_FETCHES,
        NUMBER_BIGGER_OR_EQUAL_TO_WHAT_IS_ABOVE,
        defaultBuckets);
    PoolFactory factory = new PoolFactory(
        PoolConfig.newBuilder()
              . setSmallByteArrayPoolParams(smallByteArrayPoolParams)
              .build());

Let us know how it goes.

@michalgr thank you for your suggestion
Best wishes~

i will try soon and give feedback

@michalgr You are right Thank you very much
below code work fine wor me hope this will help others:
MaxRequestPerTime = 64
SparseIntArray defaultBuckets = new SparseIntArray();
defaultBuckets.put(16 * ByteConstants.KB, MaxRequestPerTime);
PoolParams smallByteArrayPoolParams = new PoolParams(
16 * ByteConstants.KB * MaxRequestPerTime,
2 * ByteConstants.MB,
defaultBuckets);
PoolFactory factory = new PoolFactory(
PoolConfig.newBuilder()
. setSmallByteArrayPoolParams(smallByteArrayPoolParams)
.build());
ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(context,okHttpClient)
.setMainDiskCacheConfig(diskCacheConfig)
.setDownsampleEnabled(true)
.setPoolFactory(factory)
.build();

@michalgr You are right Thank you very much
below code work fine wor me hope this will help others:
MaxRequestPerTime = 64
SparseIntArray defaultBuckets = new SparseIntArray();
defaultBuckets.put(16 * ByteConstants.KB, MaxRequestPerTime);
PoolParams smallByteArrayPoolParams = new PoolParams(
16 * ByteConstants.KB * MaxRequestPerTime,
2 * ByteConstants.MB,
defaultBuckets);
PoolFactory factory = new PoolFactory(
PoolConfig.newBuilder()
. setSmallByteArrayPoolParams(smallByteArrayPoolParams)
.build());
ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(context,okHttpClient)
.setMainDiskCacheConfig(diskCacheConfig)
.setDownsampleEnabled(true)
.setPoolFactory(factory)
.build();

只有一个桶,缓存池基本没啥用啊

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenmtang picture stevenmtang  ·  3Comments

liubaoyua picture liubaoyua  ·  3Comments

sungerk picture sungerk  ·  3Comments

hbzhzw picture hbzhzw  ·  3Comments

goodev picture goodev  ·  4Comments