pdiddy
pdiddy

Reputation: 6297

iPhone didreceivememorywarning strategy

If i have a array of employees for example in my viewcontroller. Then I get the notification of low memory and the app is also not the active one.

At this point I should save the list of employees in a DB right ? so that when the user reactivate the app again, it will go through the viewDidLoad and from here I can reload the data from the DB?

Is this a good strategy?

I'm fairly new into iPhone dev.

Upvotes: 1

Views: 160

Answers (1)

rmaddy
rmaddy

Reputation: 318944

You should save any unsaved changes as soon as your app enters the background. Your app could be terminated at any point in the background without ever receiving any notifications of any kind. If your data isn't saved, it will be lost when the user restarts the app.

With regard to memory warnings, these are more likely to happen in the foreground. Once your app is in the background, it is suspended and won't get any notifications. If your app is running under iOS 5 or earlier then a memory warning could result in a view controller's viewWillUnload method being called. When that view controller needs to be displayed again, its viewDidLoad will be called again. Under iOS 6, this doesn't happen anymore. viewWillUnload is deprecated.

Upvotes: 3

Related Questions