[英]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 我没有使用ARC,因此我正在考虑在以下位置释放root_view_controller
- (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 ? 并且:在释放root_view_controller之前,还应该添加其他任何清理代码吗?
- (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 如果要释放Root_View_Controller,则需要使用dealloc方法(如上面的代码)进行释放
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. 因为当应用终止时,它所使用的内存仍然会释放。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.