Get Notified of Low Memory Crashes - ios

I am trying to find a way to capture low memory crashes.
Most crash reporting tools, for example Crashlytics, do not capture low memory os kills.
https://twitter.com/crashlytics/status/235018252647010304
http://support.crashlytics.com/knowledgebase/articles/123408-do-you-catch-out-of-memory-crashes
Does anyone know of any crash reporting tools that catch low memory crashes?
Or, does anyone know of a way to detect these crashes w/out any added reporting tools?
Thanks!

You can't "catch" a low memory warning, but you can be notified in advance of them happening. You can implement applicationDidReceiveMemoryWarning: in your app delegate or respond to the UIApplicationDidReceiveMemoryWarningNotification. Aside from that, your app isn't notified when it's terminated.
You can also store transient data in NSCache, and it'll disappear under memory pressure.

Related

Got memory pressure notification (critical) in iOS

I am downloading media contents from server and app crashes after certain time by giving following error:
Got memory pressure notification (critical)
Removed all object when I get warning in didReceiveMemoryWarning function but no luck.
How can I resolve this crash? Is there any way that I can restart the view controller after freeing all memory?
Make sure you are not retaining anything in memory from all the stuff you download. There are some API calls (like imageNamed for instance) that store things into a memory cache and that will kill your app if you do too much of it too quickly.
Also crashlogs won't help. You should check memory usage in instruments to see where it's going.

How to detect an OS forced App Shutdown

I am working on a iOS Application for >=iOS8 Devices. My app is memory intensive which becomes a problem since the app can crash. I have CrashLoggers in place that report crashes on the app during the next start. However there are certain scenarios when the app may consume higher than usual memory and the OS may terminate it. Is there any delegate that I could use to detect an OS forced app termination?
I tried [AppDelegate applicationWillTerminate:] and [AppDelegate applicationDidReceiveMemoryWarning:] but they are going to give me false positives for the most part. The problem is that this is not a exception, but a system signal raised by OS to kill the app that I am trying to detect within the scope of the event.
I am a new programmer. Let me know if I am understanding things incorrectly or I am making impractical assumptions.
I have read the following links:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/applicationWillTerminate:
Is there any method in appDelegate which is called when application crashes?
I understand that preventing the problem is better than cure. But here I am trying to detect if there's going to be a problem. It's not like the app always crashes. There may be some edge case scenarios or users on very old devices like iPhone 4s/iPad Air 1 for which the app can run (possibly) into problems. So, I need a logging mechanism around this.
The runtime of the app is ~120MB worst case which is high but well under the range of too high. While the app has a lot of features, Image processing in the app is difficult to perform while maintaining the quality and also to profile in terms of memory(spikes depend on size, quality of image, lighting, etc.). So my app is well within the boundary line, and I am asking for way to detect if the app crosses this boundary when used by the user.
I totally agree with optimization(or fixing the crash) suggestion that you gave, and I would try my best to optimize(or de-bug) the app.
When app crashes or is killed by the system, there is no signal that you can catch meaningfully.
What makes you think applicationDidReceiveMemoryWarning: is giving you false warnings?
Receiving a memory warning and then not being killed is not a false positive. That just means your app didn't increase memory allocations enough to cross the threshold.
When you receive a memory warning, log if you want, but also decrease memory usage.
How do you know that the maximum runtime allocation footprint is 120MB? Depending on device, you'll have anywhere from around 125MB (iPad 1) to well over 1GB of memory available on modern devices (more on iPad Pro).
You should be getting your applicationDidReceiveMemoryWarning: called when the system is under memory pressure. This can be simulated by selecting the Simulate Memory Warning menu item in the Hardware menu.
If you actually go over your memory limit on device, you'll get jetsamed (SIGKILLed). You can't detect that.
If you want to simulate the jetsam, just send your process a SIGKILL (kill -9 <pid>)

Send low memory crash reports with QuincyKit?

Is there a way to send low memory crash reports with QuincyKit?
I looked through the code, and QuincyKit sends the crash reports found in:
/var/mobile/Application//Library/Caches/crashes
However when the app crashes due to a memory warning a file doesn't get created in that directory. I can view the low memory reports in Organizer (type Unknown), but where is the file located?
Can QuincyKit be modified quickly to send the memory reports?
Unfortunately this is not possible.
Out of memory crashes are actually kills by the watchdog process. Whenever you kill a process, there is no crash happening. The crash reports for those that you see in Organizer, are arbitrary reports written by the watchdog process that did the kill. So the only system that can provide information about these, is iOS itself.
It is not possible to retrieve the memory reports.
However, it would be possible to notice:
that a memory warning had been received and record the memory usage at that time - and
that X seconds later the application was no longer running (by maintaining a simple watchdog thread).
You could then deduce on the next run that the application had probably been killed due to an out of memory condition, and you would have some information about the memory usage at that time. Indeed, you could extend your memory warning handler to report the size of any caches you were running (and also to clean them up at the same time, thereby reducing the likelihood of a crash!).

iOS - Received memory warning

The app plays video n audio from the bundle. When I'm testing the app on my iPod Touch, SOMETIMES just before the video is getting played, it logs the message. sometimes when the app wants to prepare the audioplayer (in another viewController) it logs the message.
However I haven't had a crash YET! :D I'm not sure if there's gonna be a crash if it runs on other devices which have multiple apps open.
So, should I worry about this? should I prepareAudioPlayer or moviePlayer in another thread?
or just ignore it?
Even if you prepare it on other threads it will not solve this issue, what you have to do is to prepare your self for when you recieve a memory warning to act upon it and free some memory that you dont need
Try to free some memory up, optimize your application memory consumption, using lazy loading technique and so on, but using another thread is definitely not a solution

Can an iOS application receive a memory warning in the background?

When an application is in the background and another application is running and is requiring more memory, can the app in the background receive a memory warning? Or can it only get killed from the memory without any warning?
If it's the latter, should I manually free up memory (cache) in the "applicationDidEnterBackground" method so that there is less chance that it will get killed?
Thank you very much!
Yes, your application can receive a memory warning while in the background. Your application only gets killed immediately if the system really needs the memory, but it'll play nice and ask your application to return memory on its own first. If the system is satisfied it won't kill your application.

Resources