in App Delegate do I need to release my "window" and "navigationController"?
In App Delegate do I:
- need to release my "window" and "navigationController"? and
- 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;
}
.
.
As Bolt clock commented you need to add a dealloc method in appDelegate class.
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
Well @greg if you ever release your window or navigationController in applicationDidReceiveMemoryWarning
dont u think your application will crash when ur application receives memory warning.
As @Bolt and @ishu said you need to release it in dealloc methods only.
Also in applicationDidReceiveMemoryWarning
method you can release those class variables which are not going to be used after some point of time, as releasing them may cause your app to crash.
So choose wisely what variables are not important that might cause your application to crash or stop your app from working properly.
精彩评论