I have two controllers. In the first one, there is a buttn and when it is clicked, the second one will be shown by the presentModalViewController
method. However, when I go back to the first one, the dismissModalViewController
is called and the second controller is dissmissed but memory is not released. I used instrument to observe memory allocations and arc.
I thought I might did something wrong but I tried the official sample code, iPhoneCoreDataRecipes and CoreDataBooks, this also happend. I am wondering why the momery was not released?
Following is the code for presentModal and dismissModal from the official sample recipes:
- (void)add:(id)sender {
RecipeAddViewController *addController = [[RecipeAddViewController alloc] initWithNibName:@"RecipeAddView" bundle:nil];
addController.delegate = self;
Recipe *newRecipe = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:self.managedObjectContext];
addController.recipe = newRecipe;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[addController release];
}
- (void)recipeAddViewController:(RecipeAddViewController *)recipeAddViewController didAddRecipe:(Recipe *)recipe {
if (recipe) {
// Show the recipe in a new view controller
[self showRecipe:recipe animated:NO];
}
// Dismiss the modal add recipe view controller
[self dismissModalViewControllerAnimated:YES];
}
I did similar things but I used arc instead so I do not have release lines.