Reputation: 942
I'm seeing some unexpected behavior when I trigger a simulated memory warning and I'm hoping someone can explain.
My application contains a UITabBarController and a UINavigationController. All my UI is created programmatically, nothing is loaded from a NIB. In my delegate function applicationDidFinishLaunching I create the tab controller, nav controller, and five view controllers. When I trigger the memory warning the main view turns completely white, leaving the nav at the top and tab at the bottom. When I change tabs the new tab reloads it's data correctly as loadView is correctly called, however the nav controller disappears.
This confuses me for two reasons. 1) Why is the main view being unloaded? I did not think viewDidUnload would be called on active view controllers. 2) Why does my nav controller disappear, but only after changing tabs. That is a real mystery.
Thanks.
Upvotes: 1
Views: 1978
Reputation: 942
The issue boiled down to how I was using UIViewControllers, UIViews, and the UINavigationController. I had 5 view controllers which dynamically swapped between ~3 views each. It was a little weird and a by product of it being my first iOS project and not understanding the "Apple Way".
In the end I simple removed all notion of a UINavigationController from my app and wrote my own. I don't use animation from one view to the next so this was incredibly simple and easy to do.
Lesson learned.
Upvotes: 1
Reputation: 1754
That sounds like a memory issue. You probably need to retain
the objects you create for UITabBarController and UINavigationController.
In the unload-method, you then need to release those.
There is an excellent manual from Apple explaining the memory management in Objective C: "Memory Management Programming Guide". Very clear and helpful.
Upvotes: 1