1

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.

Community
  • 1
  • 1
Rushabh
  • 651
  • 5
  • 15
  • 3
    "*My App is memory intensive which becomes a problem since the App can crash"* - what? An app should **never** crash - me personally would hope you cannot react to it, fix your code, dont react to crashes, fix the code causing the crash. How much memory are you using and much more important - *why*? – luk2302 Dec 10 '15 at 20:10
  • Possible duplicate of [ios simulator appear with UDID in xcode 6](http://stackoverflow.com/questions/26211593/ios-simulator-appear-with-udid-in-xcode-6) – Jeremy Huddleston Sequoia Dec 10 '15 at 21:13
  • 1
    I can't relate my question to the above post. Both are very different questions. – Rushabh Dec 10 '15 at 21:21

2 Answers2

1

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).

bbum
  • 162,346
  • 23
  • 271
  • 359
  • 1
    Its going to give a warning, I am looking for a way to detect a full hard crash which I could log somewhere. There's a chance that my App is warned but still continues to live. That would be the false positive here – Rushabh Dec 10 '15 at 20:51
-3

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>)

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86