开发者

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;
}


.
.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜