Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throwing OutOfMemoryError "Failed to allocate a 31961100 byte allocation with 4194304 free bytes and 27MB until OOM

Tags:

android

I am loading image to image-view from JSon. JSon only bring the path of image URL. I am setting the value using picasso. but it gives error for some image and for rest it is working fine.

Picasso.with(context).load(rowItem.getProductImages().get(0)).into(holder.productImageView);

error is :

 2771-2793/com.koove E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 31961100 byte allocation with 4194304 free bytes and 27MB until OOM"
03-25 09:53:23.666    2771-2793/com.koove D/skia﹕ --- decoder->decode returned false
like image 484
Vikram singh Avatar asked Mar 25 '15 05:03

Vikram singh


1 Answers

You should use the method fit() in Picasso, it's measuring the dimensions of the target ImageView and internally uses resize() to reduce the image size to the dimensions of the ImageView.

The advantage is that the image is at the lowest possible resolution, without affecting its quality. A lower resolution means less data to be hold in the cache.

Picasso.with(context).load(rowItem.getProductImages().get(0)).fit().into(holder.productImageView);

If you still have the OOM, remove the cache using the memory policy.

Picasso.with(context).load(rowItem.getProductImages().get(0)).memoryPolicy(MemoryPolicy.NO_CACHE).fit().into(holder.productImageView);
like image 170
Lilo Avatar answered Sep 22 '22 14:09

Lilo