Throwing OutOfMemoryError "Failed to allocate distribution by 31961100 bytes with free bytes 4194304 and 27 MB until OOM

I am loading an image into an image from JSon. JSon only cites the path to the image URL. I set the value using picasso. but it gives an error for some image, and for rest it works fine.

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

error:

  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 
+6
source share
1 answer

You must use the fit () method in Picasso, which measures the size of the target ImageView and internally uses resize () to reduce the size of the image to ImageView.

The advantage is that the image has the smallest possible resolution without affecting its quality. Lower resolution means less data to cache.

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

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

 Picasso.with(context).load(rowItem.getProductImages().get(0)).memoryPolicy(MemoryPolicy.NO_CACHE).fit().into(holder.productImageView); 
+4
source

Source: https://habr.com/ru/post/984223/


All Articles