I have a project that I created by using Xcode’s Single View Application template. Obviously, it comes with a view controller and an app delegate file. Everything works fine. I just wanted to use Xcode’s Analyze tool for the first time to make sure everything is fine before submitting to the App store. I get the potential leak error for the following lines of code in the app delegate:
self.viewController = [[myViewController alloc] initWithNibName:@"myViewController" bundle:nil];
self.window.rootViewController = self.viewController;
Full app delegate is as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[myViewController alloc] initWithNibName:@"myViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I didn’t modify the app delegate myself. I am using whatever the template gave me. Do I need to release something somewhere in the app delegate? If so, what? and in which method of app delegate?
Nothing needs to be released in the application delegate since the app is terminating and the OS will recover all resources. Indeed, it is improbably that dealloc will even be called.
See SO link for more information.
If you need to do cleanup when the app quits, use
applicationWillTerminate:.