OutOfMemoryError
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.


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

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
How many images do you have loaded on-screen?
Could you attach a hprof file? See the instructions on how to generate them.
@tyronen I updated the issue with the information you asked me. Thanks!
@tyronen Do you need more details?
This issue occured on my project too. Hope resolve this ASAP
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 good workaround! Thanks :)
+1
OOM when i load this gif.
me too @tyronen
@tyronen just wanted to know if there is any update on this. Thank you!
@tyronen any news? Sorry to bother you, but this is killing our app.
@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:
- Set
android:largeHeap=truein your app's manifest. - 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
getMaxCacheSizeinstead 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?
@ThomasWang2014: your issue should be fixed in v0.8.0.
@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 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.