I am using UIImagePickerController to take a photo from the camera. However, the I find that randomly my calling controller (the one that is shown before the UIImagePickercontroller is shown) gets unloaded. I logged the viewDidUnload, and indeed it does get called. When the camera is done and dismissed, my controller’s viewDidLoad will be called, unfortunately all the state is now gone. Things like text entered or things selected will be gone.
Obviously this is something to do with running out of memory. But is this behavior normal? Should I be handling it? This is NOT typically how modalViewController works. Usually you show it and dismiss it, everything should be intact.
What is a good way to avoid data lost in this case? Should I have to write a bunch of code to save the full state?
It’s really not advisable to override
-didReceiveMemoryWarningso that UIViewController can’t deallocate the view because then you may run into a “real” problem of low memory and your app will be forced to quit by the system.What you really should do is store the text and other bits of entered data from the view in your
-didReceiveMemoryWarningmethod (making sure to call super). Then in-viewDidLoadyou can put the text and other bits back into the UI.This will lighten the memory usage and reduce the likelihood of your app being forced to quit because there’s no more memory left. All the while, the user won’t know it ever disappeared!