Vikram singh
Vikram singh

Reputation: 375

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

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

Upvotes: 6

Views: 10619

Answers (1)

Lilo
Lilo

Reputation: 2734

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

Upvotes: 5

Related Questions