简体   繁体   中英

Releasing root view controller

I have the following statement inside

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

The statement is :

root_view_controller = [[Root_View_Controller alloc] initWithNibName:@"Base_View" bundle : nil];

I am not using ARC, so I am thinking of releasing root_view_controller in

- (void)applicationWillTerminate:(UIApplication *)application

My question is : Is the above practice ok ? And : Is there any other clean up code that should be added before releasing root_view_controller ?

AppDelegate.m

- (void)dealloc
{
    [_window release];
    [_viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[MLViewController alloc] initWithNibName:@"MLViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

If you want release your Root_View_Controller you need to do it in dealloc method like the code above

There is no need to release memory in

- (void)applicationWillTerminate:(UIApplication *)application

because when an app is terminated, the memory it used is released anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM