Search code examples
iphoneiosmemory-managementuinavigationcontrolleruiapplicationdelegate

in App Delegate do I need to release my "window" and "navigationController"?


In App Delegate do I:

  1. need to release my "window" and "navigationController"? and
  2. where abouts should I release it out of (a) applicationDidReceiveMemoryWarning and (b) dealloc?

Code Listing

@interface weekendviewerAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow                        *window;
    UINavigationController          *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@implementation weekendviewerAppDelegate
@synthesize window;
@synthesize navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
    rootViewController.managedObjectContext = self.managedObjectContext;
    self.window.rootViewController = self.navigationController;

    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

    return YES;
}


.
.

Solution

  • As Bolt clock commented you need to add a dealloc method in appDelegate class.

    - (void)dealloc {
    
        [navigationController release];
        [window release];
        [super dealloc];
    }