I’ve just been reading this post on notifications being sent to apps running in the background :
Not getting didReceiveMemoryWarning when app is in the background
My question is that since an app in the background will not act on a didRecieveMemoryWarning until it enters the foreground again, what is the recommended way to free up memory in your app if it is running in the background when the memory notification is sent – or is this not possible ?
In iOS 4.0 and later,
- (void)applicationDidEnterBackground:(UIApplication *)applicationmethod is called instead of theapplicationWillTerminate:method when the user quits an application that supports background execution.You should use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
You should also disable updates to your application’s user interface and avoid using some types of shared system resources (such as the user’s contacts database). It is also imperative that you avoid using OpenGL ES in the background.
Your implementation of this method has approximately five seconds to perform any tasks and return. If you need additional time to perform any final tasks, you can request additional execution time from the system by calling
beginBackgroundTaskWithExpirationHandler:. In practice, you should return fromapplicationDidEnterBackground:as quickly as possible. If the method does not return before time runs out your application is terminated and purged from memory.