fresco icon indicating copy to clipboard operation
fresco copied to clipboard

OutOfMemoryError

Open mheras opened this issue 11 years ago • 15 comments

Hello,

I'm using Fresco in a RecyclerView. I'm recycling the views properly and, of course, initializing Fresco just once in the Application class.

I see that there are other OOM issues reported, but all of them seem to occur due to huge images trying to be loaded into the memory.

In my case, as you can see in the following screenshots, the images are small.

screen shot 2015-08-27 at 10 41 42

screen shot 2015-08-27 at 10 47 50

It seems it's only happening on Android 5.0+ with ART:

screen shot 2015-08-27 at 10 48 28

Any idea how to solve this issue? I have too many occurrences of these crashes :(

EDIT 1:

I am loading 6~8 images on-screen, at most. All of them are JPEGs of ~~250~~ 25 kB max. Here's the hprof file (heap dump).

Thank you in advance, Martin

mheras avatar Aug 27 '15 13:08 mheras

How many images do you have loaded on-screen?

Could you attach a hprof file? See the instructions on how to generate them.

tyronen avatar Aug 27 '15 15:08 tyronen

@tyronen I updated the issue with the information you asked me. Thanks!

mheras avatar Aug 27 '15 17:08 mheras

@tyronen Do you need more details?

mheras avatar Aug 28 '15 19:08 mheras

This issue occured on my project too. Hope resolve this ASAP

tbruceyu avatar Sep 02 '15 17:09 tbruceyu

Hey @mheras and @tbruceyu,

We encountered similar issue at work. Our team finally ended up creating a custom BitmapMemoryCacheParamsSupplier to be supplied when initialising Fresco, as a workaround for this issue. The code is at https://gist.github.com/sensen/a61eb1e7a1b7ea649cb0.

Hopefully the Fresco team could crack this issue on their end.

sensen avatar Sep 04 '15 03:09 sensen

@sensen good workaround! Thanks :)

mheras avatar Sep 10 '15 04:09 mheras

+1

gajicm93 avatar Sep 12 '15 22:09 gajicm93

OOM when i load this gif.3e01211e0b6bdf6e9877f9193cf6844b

ThomasWang2014 avatar Sep 15 '15 03:09 ThomasWang2014

me too @tyronen

xialixue007 avatar Sep 21 '15 01:09 xialixue007

@tyronen just wanted to know if there is any update on this. Thank you!

mheras avatar Sep 21 '15 03:09 mheras

@tyronen any news? Sorry to bother you, but this is killing our app.

mheras avatar Oct 02 '15 21:10 mheras

@mheras: Your heap dump shows a total memory footprint of 56 MB. I'm going to assume this was on a device with a 64 MB heap, so the OOM risk is high.

On such a device, the bitmap cache is by default limited to 16 MB. If your app is finding that hard, there are two possible solutions:

  1. Set android:largeHeap=true in your app's manifest.
  2. Adjust the size of the cache along the lines @sensen suggested. His code limits the cache to just one entry on Lollipop, which is probably not what you want. You can try changing the code of getMaxCacheSize instead to give you a smaller cache for the 64MB devices - perhaps 8MB would work better for you, rather than the 16MB we use by default.

I notice also you seem to be using Picasso and Fresco simultaneously. Each of these libraries operates its own memory cache; putting both together on a low-end device is going to be hard. Do you need both? Are there features Picasso provides your app that Fresco does not?

tyronen avatar Oct 16 '15 13:10 tyronen

@ThomasWang2014: your issue should be fixed in v0.8.0.

tyronen avatar Oct 19 '15 23:10 tyronen

@tyronen

We are transitioning from Picasso to Fresco, but the app is huge and we are still working on it.

Aside from that, my question is:

If the available heap is not enough for the upcoming image, shouldn't the library try send the least recently used images back to disk so that more heap memory becomes available for such image? Am I missing something else?

Thanks

mheras avatar Nov 18 '15 13:11 mheras

@mheras we do do this. Your app's problem is this:

Fresco uses 1/4 of the heap size. If this is filled up, images are swapped out but remain on disk. Picasso uses 1/7 of the heap size. If this is filled up, images are swapped out but remain on disk.

The rest of your app is thus limited to around 60% of the normal heap. If your app ever needs more than that, it will OOM.

You either have to reduce Picasso or Fresco's memory footprint by reducing the cache size, OR reduce the rest of your app's footprint.

tyronen avatar Jan 05 '16 13:01 tyronen