I have a question about the memory management. In my app delegate, I have the following method; where welcomeViewController is an ivar.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
welcomeViewController = [[CBWelcomeViewController alloc] init];
UINavigationController *appNavigationController = [[UINavigationController alloc] initWithRootViewController:welcomeViewController];
[self.window addSubview: [appNavigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
To release the memory for welcomeViewController, I simply call release on it in the dealloc method.
- (void)dealloc {
[welcomeViewController release];
[window release];
[super dealloc];
}
My question is, what is the correct way to manage the memory of appNavigationController?
You should make
appNavigationControlleran instance variable andreleaseit indealloc.You do not need to have
welcomeViewControlleras an instance variable, quite the opposite.Simply alloc/init it, then pass it off to the
UINavigationController, which then retains it, then immediatelyreleaseit.