[Wish] Catch OutOfMemory errors

Informatix

Expert
Licensed User
Longtime User
Java Errors are not meant to be caught, unlike Exceptions.

You can create a library method that will start a sub (with raiseEvent) and catch errors:
B4X:
try {
 ba.raiseEvent(...)
} catch (Throwable t) {
 throw new RuntimeException(t);
}

It's currently what I do for my own projects but that's of no help to anyone but me. When I see the number of posts here about OOMs, it could be useful to catch these errors. I already read many articles about the pros and cons to catch the throwables. Sometimes, it's better to let them crash the app (like ClassNotFound) because that reveals bad code or programming errors behind, but I saw no real arguments for OOM (every Android app should be able to handle this case because it's not unlikely). When you have 28MB free and the app crashes for a bitmap needing only 5 MB (because the memory is too fragmented), that's a bit frustrating to not be able to recover from it.
 

NFOBoy

Active Member
Licensed User
Longtime User
Concur

Currently, I am using Agraham's gifdecoder, and reports from devices on Out Of Memory errors are received every week, (I'm assuming they are from lower-end devices, but I can't tell), and I can't decipher how much smaller I need to make the gif (and still have it look ok on displays) based on those low-end memory errors. If try.. catch worked on these.. then I could just have the program skip by that (it's just my opening logo) and continue on to the rest of the show.

If there was a way to test if loading a bmp was going to cause the error, then fine, but right now... just OOM... and done. (and I cannot get my devices to give me this error.. and trying to figure out what device I need to go buy, so that I can replicate... is near impossible with data I see on the errors sent to my account)

I wouldn't mind doing the build your own library thing, but, as stated.. it happens enough, and with it just being the OOM due to fragmented, or smaller memory limits, at least I could put code in to try (and catch) these pesky errors.

Ross
 

Woinowski

Active Member
Licensed User
Longtime User
Would appreciate the feature, too.

I suspect some of my users crash reports to be caused by OOM, and would like to at least give a friendly "sorry for that" message...
 

Joe_L

Member
Licensed User
Longtime User
It's essential to catch OOM (indeed all exceptions) so the app can handle things gracefully (even if it can't continue with the operation it can at least be kind to the user), and also so the developer can be provided good instrumentation. Otherwise the user experience is poor and the reputation of the app/developer/development platform suffers.

Checking memory in advance is inadeqaute because of the fragmentation Informatix pointed out.
 

Inman

Well-Known Member
Licensed User
Longtime User
Starting from the next version out of memory exceptions related to bitmaps will be handled internally. I believe that this will solve 99% of the OOM errors.

That will be awesome. Can't wait!
 

ChrShe

Member
Licensed User
Longtime User
Just curious...Would you happen to have an E.T.A. for this?

Thanks.
 
Top