0

我里面有以下声明

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

声明是:

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

我没有使用 ARC,所以我正在考虑发布 root_view_controller

- (void)applicationWillTerminate:(UIApplication *)application

我的问题是:上述做法可以吗?并且:在发布 root_view_controller 之前是否应该添加任何其他清理代码?

4

2 回答 2

2

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

如果你想释放你的 Root_View_Controller 你需要像上面的代码那样在 dealloc 方法中做

于 2013-05-10T12:58:22.077 回答
1

不需要释放内存

- (void)applicationWillTerminate:(UIApplication *)application

因为当应用程序终止时,它使用的内存无论如何都会被释放。

于 2013-05-10T12:55:22.770 回答