This code doesn't appear to leak. To be sure, however, you should use the
leaks instrument to periodically check your code.
To do such,
- Select Product -> Profile (or, ⌘ I)
- Choose `Leaks`
- Select Profile
- Exercise your app (i.e. go through all the options, background it, etc)
For more information on using the leaks tool, you can checkout Ray Wenderlich's Instruments Tutorial for iOS: How to Debug Memory Leaks.
1) Unless you have a really good reason to, you shouldn't be setting
self.window.rootViewController every time that the app returns to the foreground. Instead of calling
showMainWindow from within
applicationDidBecomeActive, you should probably move this code within
application:didFinishLaunchingWithOptions:, which is the more common place to do initial app setup.
Further, if you need a controller to know when the app has entered the foreground (I imagine that this is the reason you're actually doing this), you should have it register to receive notification of
[[NSNotificationCenter defaultCenter] addObserver:self
// ... whatever else you do here...
// Also make sure to unregister too
[[NSNotificationCenter defaultCenter] removeObserver:self];
2) To make this code a bit more cleaner and easier to read, I would rewrite it like this:
NSLog(@"@Info @AppDelegate: Showing Main Window");
self.leftMenuViewController = [[MenuViewController alloc]initWithSide:@"left"];;
self.rightMenuViewController = [[MenuViewController alloc]initWithSide:@"right"];;
self.viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:self.webViewController
self.window.rootViewController = self.viewDeckController;
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateNavigationBar" object:nil];
In such, you don't have to explicitly set
nil or create the