I am an experienced C / C ++ programmer starting to learn Objective-C development. I am currently looking at a UICatalog sample and came across another idiom example. I saw several places and never understood.
code:
ButtonsViewController *buttonsViewController = [[ButtonsViewController alloc] initWithNibName:@"ButtonsViewController" bundle:nil]; [self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"ButtonsTitle", @""), kTitleKey, NSLocalizedString(@"ButtonsExplain", @""), kExplainKey, buttonsViewController, kViewControllerKey, nil]]; [buttonsViewController release];
AFAIK, this selects and initializes the ButtonsViewController, creates an NSDictionary for the ButtonsViewController and adds a dictionary to the NSMutableArray called menuList (which is the MainViewController member variable where the above code is located), and then releases the ViewController buttons that it just created. Later, MainViewController uses a dictionary entry to switch views to buttonViewController when necessary.
My question is: why is the buttonViewController still valid after this code? It was isolated and released without "saving" between them. Does something in NSDictionary or NSMutableArray add implicit "persistence"? If so, should I somehow figure it out, or is it just one of those things that you have to read and remember?
source share