Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out Of Memory Error decoding image on Lollipop #468

Closed
anshu56 opened this issue Jul 17, 2015 · 6 comments
Closed

Out Of Memory Error decoding image on Lollipop #468

anshu56 opened this issue Jul 17, 2015 · 6 comments
Labels
needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem)

Comments

@anshu56
Copy link

anshu56 commented Jul 17, 2015

Hello,

We recently released Fresco in our production app and we're seeing a lot of crashes from OutOfMemory errors, looking at the stacktrace it looks like it's happening during decoding the image. The interesting thing is that all of these crashes are only happening on Lollipop, none of them happen on pre Android L devices. We are using a memoryTrimmableRegistry, and calling the trimMemory functions when we receive an onMemoryTrim() call from our activity.

This seems to be happening on pages where users are interacting with a view pager of images. The views we are using in the pager are either just a SimpleDraweeView, or a ZoomableDraweeView which is based on the provided sample. When we initially implemented this we were seeing TooManyBitmaps exceptions and it looked like it was because the pager adapter wasn't releasing the images even though they were removed from the container. To solve this we added in this bit of code in our PagerAdapter.destroyItem() override, does it look like this could somehow cause any issues?

        if(view instanceof GenericDraweeView) {
            view.onStartTemporaryDetach();
        }

Do you have any idea what could be causing this, is there any more information we can provide?

The stacktrace is included below

java.lang.OutOfMemoryError: Failed to allocate a 4367372 byte allocation with 3423299 free bytes and 3MB until OOM
       at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
       at android.graphics.Bitmap.nativeCreate(Bitmap.java)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:939)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:912)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
       at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:55)
       at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:30)
       at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:260)
       at com.facebook.imagepipeline.bitmaps.ArtBitmapFactory.doDecodeStaticImage(ArtBitmapFactory.java:131)
       at com.facebook.imagepipeline.bitmaps.ArtBitmapFactory.decodeJPEGFromPooledByteBuffer(ArtBitmapFactory.java:119)
       at com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory.decodeJPEGFromPooledByteBuffer(PlatformBitmapFactory.java:106)
       at com.facebook.imagepipeline.decoder.ImageDecoder.decodeJpeg(ImageDecoder.java:140)
       at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:84)
       at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:166)
       at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$000(DecodeProducer.java:88)
       at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:112)
       at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:109)
       at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:214)
       at com.facebook.imagepipeline.producers.JobScheduler.access$000(JobScheduler.java:30)
       at com.facebook.imagepipeline.producers.JobScheduler$1.run(JobScheduler.java:68)
       at com.facebook.common.executors.SerialDelegatingExecutor.executeSingleCommand(SerialDelegatingExecutor.java:76)
       at com.facebook.common.executors.SerialDelegatingExecutor.access$000(SerialDelegatingExecutor.java:24)
       at com.facebook.common.executors.SerialDelegatingExecutor$1.run(SerialDelegatingExecutor.java:47)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
@michalgr michalgr added the needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem) label Jul 17, 2015
@michalgr
Copy link
Contributor

It is normal that there are no OOMs pre to Lollipop. It would be useful to know some numbers here: how many bitmaps do you display simultaneously ? And what are their sizes ?

@anshu56
Copy link
Author

anshu56 commented Jul 17, 2015

Hmm that's interesting, why would we expect OOM crashes on Lollipop and not on older os versions?

We display our images in a viewpager, displaying a single image at a time. We will cache the previous 2 and next 2 views in the pager, for a total of 5 images. If you click on one of the views, we'll take you to a full screen viewpager with zoomable drawee views. It's the same thing here, displaying an image 1 at a time caching 2 in either direction. The images are just a few hundred kb in size. An example of 5 images that might be loaded are available at these urls:

http://media.cdn-redfin.com/photo/1/bigphoto/183/819183_0.jpg
http://media.cdn-redfin.com/photo/1/bigphoto/183/819183_1_0.jpg
http://media.cdn-redfin.com/photo/1/bigphoto/183/819183_2_0.jpg
http://media.cdn-redfin.com/photo/1/bigphoto/183/819183_3_0.jpg
http://media.cdn-redfin.com/photo/1/bigphoto/183/819183_4_0.jpg

@michalgr
Copy link
Contributor

On pre-Lollipop androids we store images off the java heap. Google killed that trick in Lollipop.

Each of those images seem to be ~ 1024 x 700 pixels, which gives us 2.7MB per Bitmap. There should be enough place to store a few of those.

What is the max heap size ? You can try making Bitmap cache smaller: http://frescolib.org/docs/configure-image-pipeline.html#configuring-the-memory-caches

@anshu56
Copy link
Author

anshu56 commented Jul 20, 2015

Thanks for your help and the prompt responses @michalgr. Sorry for the false alarm, but we actually pinned the issue down to our handling of the view pager, we just got a bit concerned when we were seeing it happen in production. I'll go ahead and close this issue.

@anshu56 anshu56 closed this as completed Jul 20, 2015
@LinJZong
Copy link

It have the some problem.My app will display a lot of images in different activity using Fresco.It works well on pre Android L devices,but crash on Lollipop.My images are very small(10-20K).I guess Fresco won't recycle the memory on Lollipop .

@michalgr
Copy link
Contributor

@LinJZong: please open separate issue and include more details, like what are the dimensions of decoded Bitmaps and what container view do you use (ListView, ScrollView, RecyclerView etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem)
Projects
None yet
Development

No branches or pull requests

3 participants