Hello,
in the very good book "Beginning iPhone Development" (Apress), in the Chapter 9, they explain how to build an application with a navigation controller and hierarchical table views.
If you launch the application with Instrument/Activity monitor, the application working well but with a big problem : each time you drill down from table views into child tables, it takes 1Mo of memory more! and this memory is never released and of course, at the end the application crash.
For me the problem come from the following method of "RootViewController.h":
(the original source code is "09 Nav" of the this ZIP file )
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
SecondLevelViewController *nextController = [self.controllers objectAtIndex:row];
NavAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navController pushViewController:nextController animated:YES];
}
in this method "nextcontroller" is never released. in order to use the command [nextController release]; I have made the following modification:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
SecondLevelViewController *nextController = [[SecondLevelViewController alloc] init ];
nextController = [self.controllers objectAtIndex:row];
NavAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navController pushViewController:nextController animated:YES];
[nextController release];
}
Now, if you run the application, the memory is well released! But if you try to drill down in a child table where you have already "visited", the application crash.
How can we release the memory properly?
Thank you in advance.