Skip to content Skip to sidebar Skip to footer

Out Of Memory Error In Picasso

I am using picasso library for loading multiple images on grid from server. I have three fragments on main activity.Each fragment loads multiple images on grid from server using pi

Solution 1:

Similar ques. Android Picasso ImageView - Out of Memory Exception MemoryLeak

When Android "unwraps" your image (i.e. decodes it to bitmap), it will use 4 bytes per pixel. Count the number of pixels, multiply that by 4 and then by 20 (number of your images) and you'll probably get close to the 100mb figure. For instance, if your images have 1,000,000 pixel resolution, it would be 1,000,000 x 4 x 20 = 80mb.

Use some kind of LRU cache or similar (or alternatively use Universal Image Loader library which handles caching for you) and only load your bitmaps when you need them.

Solution 2:

Try Fresco library from Facebook. Earlier, I was also using Picasso and used to get OOM error as the heap size allocated to an app is very small and can quickly become full if you are loading images of large size. Fresco uses ashmen cache which allows for much more data to be cached. It also has an option of downsampling the images and progressive loading of JPEGs. I have not faced any OOM issues since I switched to Fresco. Do try it. Also, try to use OkHttp as the networking library. It provides http caching which might help too. Plus enable largeHeap as written by @codephillip. That helps a bit too.

Post a Comment for "Out Of Memory Error In Picasso"