1

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.

0

2 Answers 2

1

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.

4
  • 1
    It might help if you posted some code. How do you create your controllers, how are the properties declared?
    – Axel
    Feb 1, 2011 at 9:41
  • I don't think it's a retain issue. If that were the case then it would crash immediately. My only problem is that when I select "simulate memory warning" the OS is forcing a view to dealloc when it's active.
    – LordCecil
    Feb 7, 2011 at 8:08
  • (Hit enter early, oops) I don't think it's a retain issue. If that were the case then it would crash immediately. My only problem is that when I select "simulate memory warning" the OS is forcing a view to dealloc when it's active. Posting code is tricky because it's complicated. My application delegate creates a UITabBarController, UINavigationController, and 5 custom view controllers. When I "simulate memory warning" the views of all 5 view controllers are released, even though one of them is currently being used!
    – LordCecil
    Feb 7, 2011 at 8:14
  • I still think it might be a memory issue: autoreleased objects are available for an undefined amount of time and they may or may not be be valid at the moment you try to access them. This is dependent on the exact code configuration. Adding or removing one line makes a difference. Trust me - I had some of those issues.
    – Axel
    Feb 7, 2011 at 9:18
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.