Reliably forcing a background application to terminate due to memory pressure

I am trying to understand the conditions that cause the iOS system to restart an application that has been terminated due to memory pressure. Creating sufficient memory pressure was difficult.

Currently, my approach is to run my application through Xcode, create it, and run a helper application that eats memory. It allocates a bit of memory in the NSTimer loop until the iOS system kills it. When I'm lucky, Xcode tells me that my main application was “terminated due to memory pressure”.

I am looking for a more reliable way to achieve this. Are there any memory allocation methods or private APIs that are better suited for this purpose?

+4
source share
2 answers

I am a little surprised at the behavior you are describing, but a few thoughts:

  • As far as I know, iOS makes no guarantees that applications are dropped, and does not guarantee that all background applications will be dropped (or just try to reset enough applications to reduce the state of memory pressure), Handling low memory conditions in iOS and Mavericks gives some tips, but I can't vouch for that. But the OS is dealing with some kind of complex logic, so I hesitate to state any firm statements about the steps that need to be taken to ensure that certain applications will be dropped.

  • , , , . , , . , - , iOS .

    , . " " , .

    , , , - , , .

  • Xcode, , . , , . , , , , , .

    , , - (, background NSURLSession, push- ..), . , ", ".

    , , , .., Xcode . NSLog , , ( - ) ..

+5

, , , , , .

, , , (applicationDidEnterBackground:), , , loop til kill `exit (0) '. , "" Xcode, .

+1

All Articles