fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Animations crash so frequently on 5.0+ because of OOM

Open ivfuricks opened this issue 11 years ago • 11 comments

Crash log: java.lang.OutOfMemoryError: Failed to allocate a 192804 byte allocation with 164734 free bytes and 160KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) 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.a.c.c.p(AnimatedDrawableCachingBackendImpl.java:147) at com.facebook.imagepipeline.a.c.c.q(AnimatedDrawableCachingBackendImpl.java:340) at com.facebook.imagepipeline.a.c.c.i(AnimatedDrawableCachingBackendImpl.java:450) at com.facebook.imagepipeline.a.c.c.b(AnimatedDrawableCachingBackendImpl.java:52) at com.facebook.imagepipeline.a.c.f.call(AnimatedDrawableCachingBackendImpl.java:410) at a.q.run(Task.java:195) at com.facebook.c.c.b$a.run(ConstrainedExecutorService.java:178) 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)

So far this has only happened on android 5.0+

ivfuricks avatar Apr 17 '15 06:04 ivfuricks

The same problem with you. Somebody can resolve it ?

java.lang.OutOfMemoryError: Failed to allocate a 39752868 byte allocation with 8388544 free bytes and 22MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) 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:264) 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:135) at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:83) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:231) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$200(DecodeProducer.java:92) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$3.run(DecodeProducer.java:202) 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)

Uploading B78FB136-D854-4E08-A6C3-CE66BA973B26.png . . .

jkyeo avatar Apr 17 '15 10:04 jkyeo

Actually @kooze's issue is a different stack trace and not the same issue.

The size of the allocation gives me pause - this is a 39 MB image, which would be around 3000 x 3000 pixels, more than most mobile devices will need. If it is a JPEG, try resizing it first.

tyronen avatar Apr 17 '15 11:04 tyronen

Thanks @tyronen a lot. There should not be such big size image in my project. So, I need to review my code. Thank you.

jkyeo avatar Apr 17 '15 15:04 jkyeo

@ivfuricks, the animations code in Fresco is very new and there are still a few issues with it. We are working on resolving all of them. I am aware of this particular issue and I already have some changes ready in order to fix those.

plamenko avatar Apr 18 '15 00:04 plamenko

Is there any way to catch an OutOfMemoryError to avoid crash?

ghost avatar Jul 09 '15 17:07 ghost

OutOfMemoryError is a Throwable and can be caught, however that is not a solution, nor an advisable approach.

plamenko avatar Jul 10 '15 13:07 plamenko

I agree, but in cases where there is no control on the size of a PNG, resizing with Fresco can't be done, since at the moment only JPEG resizing is supported. The only way I see to avoid a crash is to catch the OutOfMemoryError. The problem is the crash happens on a thread created by Fresco and I have no way of building a try/catch on it. Any suggestions?

ghost avatar Jul 10 '15 13:07 ghost

I meet the problem too.the gif is about 500k with 2362 width and 1652 height. I also use setDownsampleEnabled(true)

I load it with DataSource<CloseableReference<CloseableImage>> dataSource = Fresco.getImagePipeline().fetchDecodedImage(request, null);

and create Animater Drawable by AnimatedImageResult img = ((CloseableAnimatedImage) image).getImageResult();

AnimatedDrawableFactory animatedDrawableFactory=Fresco.getImagePipelineFactory().getAnimatedDrawableFactory(); if (animatedDrawableFactory != null) { AnimatedDrawable animatedDrawable = animatedDrawableFactory.create(img); if (animatedDrawable != null) { return animatedDrawable; } }

I can get other smaller gifs but not all. Hope it can solve soon!

ChenSiLiang avatar Feb 17 '16 06:02 ChenSiLiang

java.lang.OutOfMemoryError: Failed to allocate a 2027788 byte allocation with 254184 free bytes and 248KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:825) at android.graphics.Bitmap.createBitmap(Bitmap.java:802) at android.graphics.Bitmap.createBitmap(Bitmap.java:769) 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:259) at com.facebook.imagepipeline.platform.ArtDecoder.decodeStaticImageFromStream(ArtDecoder.java:137) at com.facebook.imagepipeline.platform.ArtDecoder.decodeJPEGFromEncodedImage(ArtDecoder.java:120) at com.facebook.imagepipeline.decoder.ImageDecoder.decodeJpeg(ImageDecoder.java:151) at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:85) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:188) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$200(DecodeProducer.java:96) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:128) at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:207) at com.facebook.imagepipeline.producers.JobScheduler.access$000(JobScheduler.java:27) at com.facebook.imagepipeline.producers.JobScheduler$1.run(JobScheduler.java:78) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:43) at java.lang.Thread.run(Thread.java:818) Android 5.0.2 react-native 0.17

wv1124 avatar Mar 16 '16 00:03 wv1124

I meet the problem too,Anybody can tell me why? E/art: Throwing OutOfMemoryError "Failed to allocate a 8294412 byte allocation with 1530638 free bytes and 1494KB until OOM" E/AndroidRuntime: FATAL EXCEPTION: Thread-319 Process: com.zhulei.haoji, PID: 6672 java.lang.OutOfMemoryError: Failed to allocate a 8294412 byte allocation with 1530638 free bytes and 1494KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:812) at android.graphics.Bitmap.createBitmap(Bitmap.java:789) at android.graphics.Bitmap.createBitmap(Bitmap.java:756) 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:259) at com.facebook.imagepipeline.platform.ArtDecoder.decodeStaticImageFromStream(ArtDecoder.java:137) at com.facebook.imagepipeline.platform.ArtDecoder.decodeJPEGFromEncodedImage(ArtDecoder.java:120) at com.facebook.imagepipeline.decoder.ImageDecoder.decodeJpeg(ImageDecoder.java:152) at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:85) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:194) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$200(DecodeProducer.java:97) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:129) at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:207) at com.facebook.imagepipeline.producers.JobScheduler.access$000(JobScheduler.java:27) at com.facebook.imagepipeline.producers.JobScheduler$1.run(JobScheduler.java:78) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:43) at java.lang.Thread.run(Thread.java:818)

Fuge2008 avatar May 08 '17 02:05 Fuge2008

The animations code has been rewritten since this issue was filed. If the problem still persists in the new implementation please file a bug.

erikandre avatar Jun 09 '17 13:06 erikandre