I'm new to developing for iOS. I've seen a lot of documentation about controlling memory management programmatically, however I'm curious about the default way iOS handles memory when navigating between:
(Note: When I say a Master-Detail view, I am basically referring to a Navigation Controller. I'm just calling it a "Master-Detail View" to define two different levels of the Navigation Controller hierarchy, so its easier for us to discuss)
I will go through each of the 3 topics with the questions I have:
Tabs
Master-Detail view (in the case where the Master is a UITableViewController, and the Detail is just a UIViewController and they are embedded in a Navigation Controller)
Master-Detail Views with Tabs (in the case where the Master is a UITableViewController, and the Detail is just a UIViewController and they are embedded in a Navigation Controller)
All of these questions are referring to the default behavior of iOS.
A couple of thoughts:
Diagnostics: The easiest way to diagnose what's going on is to add logging statements to your child view controllers. For example, if you add the following line to the viewDidLoad
and dealloc
methods, you'll be notified as controllers and loaded and deallocated:
NSLog(@"%s", __FUNCTION__);
Then, armed with view controllers that will log as they are instantiated and deallocated, you can use these controllers in any combination of container controllers (tab bar controller, navigation controller, split view controller, etc.) and you can easily see what's going on yourself.
Regarding the specific container controllers you asked about:
Tab bar controller: In storyboards, tab bar controllers allocate the child controllers as you select their respective tabs (and not before), but keeps old tabs. (In NIBs, it just depends upon what you did programmatically; you can either preload them or not preload them.)
Navigation controller: Navigation controllers load new child controllers as you push to a particular scene, but it does not release the previous view controllers in that process. Only when you pop a view controller off the navigation stack will that controller be released.
Split view controller: As you perform a replace segue in the split view controller, it will instantiate the new child scene, and will release the previous child controller. And if that previous child controller, itself, was a container controller such as a tab or navigation controller, then its children will be released as well.