I have a custom UIViewController subclass that handles all the view initialization by itself (it doesn’t use nib). There is also another UIViewController subclass loaded from nib. Both are contained by UITabBarController.
When a memory warning comes, the first controller does receive notification, but viewDidUnload doesn’t get called. The second controller also receives notification and it’s viewDidUnload does get called.
I checked in didReceiveMemoryWarning, self.isViewLoaded is TRUE and self.view.superview is null.
Both controllers (their tabs) are invisible at the time the notification appears.
Is there something special a custom view controller should do to be unloaded in a result of memory warnings?
If you are subclassing
UIViewContollerand you do not initialize it from a NIB, you need to subclass the-loadViewmethod. Otherwise iOS assumes that the view cannot be unloaded / reloaded.It would be sufficient to just add the following to your implementation:
I will try to find a documentation quote for that.
The documentation is unfortunately not very clear on this matter.