I’ve almost finished my iPhone app and I’m making test using XCode 4 and IOS Simulator.
My App has a series of view opened modal:
View 1 –> modal –> View 2 –> modal –> View 3 –> modal –> View 4
View 2 is the delegate of View 3 and View 3 is delegate of View 4.
If View4 is visible and I try to “simulate Memory Warning” then I’m able to go back to View3, but View3 is not able to call its delegate ([self.delegate NotifySave:self]).
If I place a breakpoint before calling the delegate, I see “0x0” instead of “0xsomething”.
Even if I “quit” the application with the “home” button, the problem (of course) is still there when I run the app again.
The questions are:
- Did someone else experienced the same problem?
- Can this problem exists only with the simulator? (I’m not able to reproduce the warning on real iPhone)
- Did someone have any suggestions?
- Can I prevent View2 from being released? (I think this is the cause of the problem)
Thank everybody for the help.
If you are storing the delegate via obj-c 2.0 property, try changing your model to rely on a
retaininstead ofassign. This will ensure that the delegate is not released out from under you in these situations. If you go with this route, it is important to ensure that you do not have a “retain circle” where two objects retain each other and never get released.For backgrounding, you should develop a system that stores the info you need to restore your application state, then clear all these items out of memory on quit (in
- (void)applicationDidEnterBackground:(UIApplication *)application) and restore them on relaunch. This will prevent your application from being “purged” as often, increasing the likelihood that you’ll be able to restore on relaunch (in- (void)applicationWillEnterForeground:(UIApplication *)application), rather than your app being relaunched from square 1 each time.