Picasso Library - Out of Memory

I am using Picasso library latest version 2.4.0 in my app for downloading and caching images. There are roughly 25-30 images of size 300KB-400KB each. I think that this is no way something big or heavy.

Even though the app is running fine, I'm getting out of memory allocations in my logcat. Can anyone explain why is this happening?

Your original code was downloading the full image, loading the full image into memory, then having Android scale the image down to fit your ImageView.

In this case, you do not need the full image in memory -- you need something closer in size to what the ImageView is.

fit() on Picasso handles this. It uses inSampleSize on BitmapFactory.Options to downsample the image as it is being loaded into memory, to get you something around the size of the ImageView, letting Android scale from there. This will significantly reduce the memory footprint of each image, particularly depending on how big of an ImageView you are using.