-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
OOM on Glide error #491
Comments
Does #435's fix help you? |
Well no it does not as it's to LOG by default and OOM are a little different to handle in Java. |
Oh, sorry I thought there was a custom handler too. |
Can't you use |
You can configure it but if it's LOG by default and it crash, then the handler will obviously not be called in case of OOM as to be called it would have need to be catched ;) |
... "and that's a bad miss", good point. :) |
@sjudd could add more defensive catches, but you should be able to catch it in the meantime with |
Yes I can do lot's of things, but I also have things already handled + Crashlytics + + + +, and some OOM should still crash when on other part of the application since not recoverable. |
How large are the assets you're using for placeholders? If they're not particularly large, you probably have a memory leak, in which case try/catching around the placeholders won't do you much good, you will just OOM soon after somewhere else randomly. |
Some can be large but please read again the first part of what I do on OOM :) My app can have a large back stack depending on how the user navigate and on some devices this can be problematic, catching those and clearing backstack does recover most of the time, this is not related to memory leaks and does not remove the underlying need :) Usually it's more rob that tells me you're doing it wrong do it another way ;) |
Hah sorry, I don't mean to tell you how to write your app. My concern is mostly that it's hard to know what to do when if we do catch an OOM creating a placeholder. We can't call any of the normal error methods, because those typically also show a placeholder, so we will end up in a loop. We could add an additional failure method, but that seems redundant and confusing. I don't disagree that this could be useful, I'm just not sure I see a straightforward solution. |
Can't 2cf8671 be extended to support OOM ? Just need a new specific catch block as it's not an exception but still a throwable if it's the correct place. |
Unfortunately not, that captures exceptions thrown by the decode process on a background executor. The placeholders are retrieved from resources on the main thread. We could just set null placeholders if we catch an OOM, but then you'd have to infer that receiving a null placeholder in the Target when a placeholder was specified actually indicated an OOM, which is a little odd. |
Hi, I hope this helps! |
Hi, I need some advice about handling OutOfMemoryError. I think this should be caused by memory leaks I just call like this Glide.with(context)
.load(event.getImageUrl())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.placeholder)
.into(eventImage); the resource file placeholder is about 516 x 272 px and I think this is not large anyway 03-31 23:27:03.698 10147-10147/me.gilo.eventhub E/AndroidRuntime: FATAL EXCEPTION: main
Process: me.gilo.eventhub, PID: 10147
java.lang.OutOfMemoryError: Failed to allocate a 10890012 byte allocation with 4194304 free bytes and 10MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:58)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:54) |
@4sskick please do some more investigation of your heap: @Tolriq here doesn't have memory leaks, he just has a deep stack and active images accumulate (they're all displayed in the background behind the visible activity, this is an Android limitation). @4sskick Please open a new issue if you want to us to help investigating. Include what you find out when doing: Android Studio > Android Monitor > Memory > Dump Java Heap > Analyzer Tasks > Perform Analysis > Leaked Activities |
Hi! It would be nice if we could set some special flags on Bitmap decode options, like inPurgeable. I know it's deprecated (since Lollipop), but in our app it was the only way to avoid the OOMs, expecially in some device with Dalvik VM (where the Bitmaps sometimes can't be GC, unless you set inPurgeable). I don't know if that can be done with a custom Downsampler, like described in issue #1048... |
@andreaboi83 your best bet without modifying the source of Glide is to hack |
We handle OOMs on Glide's threads now so that they're passed back to requests. We don't have way to handle OOMs on placeholders. If someone has an idea of how that could be done coherently, please open a new issue. At the moment we'd have to just silently not show the placeholder. Given that OOMs are usually caused by other issues that are fixable, that seems like a weird default. |
Don't know if it should be handled by default or offer an option for it, but Glide can currently OOM on decoding error / placeholder drawables.
Since this happens out of application control it's impossible for the application to catch that and react accordingly.
(I normally catch those OOM and clear backstack then glide cache to recover most of the time).
The text was updated successfully, but these errors were encountered: