UPDATE: I made a mistake in my debugging – this question is not relavent – please see comment below.
Note: I am using Automated Reference Counting
When my app starts – I present a view controller inside a UINavigationController with presentViewController:animated:completion. That view controller loads a second view controller on to the navigation stack. The second view controller uses [self.presentingViewController dismissViewControllerAnimated:YES completion:nil] to dismiss itself. My issue, is that neither dealloc nor viewDidUnload are ever called in the first view controller. However, with instruments, I can see that the view controller is no longer allocated once the presented view controllers are dismissed. The code that presents the first view controller is
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// check if our context has any accounts
if( [self.accounts count] == 0 )
{
// Display the Add Account View Controller
MySettingsViewController *settingsVC = [[MySettingsViewController alloc] initWithNibName:@"MySettingsViewController" bundle:nil];
settingsVC.appContext = self.appContext;
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC];
navVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
// Display the Add Account View Controller
}
else
{
navVC.modalPresentationStyle = UIModalPresentationFormSheet;
}
[self presentViewController:navVC animated:YES completion:nil];
}
}
So, I do not have any references to settingsVC that should be sticking around but I do not know why my dealloc is not being called. Any help would be great.
They don’t get called because you haven’t correctly released your view controller.
You allocate both
settingsVCandnavVCwithallocand thus get owning references to both that you must later release which you didn’t do.You can do it like this:
An alternative would have been to
autoreleaseboth right away.