释放视图控制器是否释放其所有属性?

问题描述:

我有一个BaseViewController,它是UITabBarController的子类,并在此视图控制器中设置我的视图。释放视图控制器是否释放其所有属性?

-(void)setUpViews 
{ 
FirstController *mainViewController = [[FirstController alloc] initAssignment:delegate.currentAssignment withMutableArray:myArray]; 
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController]; 


SecondController *secondViewController = [[SecondController alloc] initWithNibName:@"SecondController" bundle:nil]; 
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 


self.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController,nil]; 

firstNavController.tabBarItem.image = [UIImage imageNamed:@"blablabla.png"]; 
firstNavController.tabBarItem.title = @"Stream"; 


secondViewController.tabBarItem.image = [UIImage imageNamed:@"blabla.png"]; 
secondViewController.tabBarItem.title = @"Favourite"; 
} 

现在我还有一个视图控制器,我把它称为ViewHandlerControllerBaseViewController一个子类。在我的viewDidLoadviewHandler,我调用setUpViews这是在BaseViewController宣布。在我的应用程序的第一个屏幕中,当按下登录按钮时,我实例化我的ViewHandlerController,并通过使用导航控制器成功地呈现了我的tabcontroller。

[[[UIApplication sharedApplication].windows objectAtIndex:0] addSubview:viewControllerHandler.view]; 

在我的应用程序中。有一个注销按钮。我正在使用NSNotificationCenter来调用我的第一个屏幕中声明的logoutMethod。我的问题是,在此注销方法中,我如何释放先前分配的对象以避免内存压力,因为用户可以再次登录(logIn-logOut -logIn)?因为我使用ARC,将我的ViewController设置为NIL会做所有的清理工作吗?

编辑:是从超视图中删除我的ViewControllerHandler,并将其设置为零有助于发布其子视图吗?

干杯

那么,回答你的问题(不ARC) - 不,基本上视图控制器释放时不释放他的属性。但是你应该在viewDidUnload和(或)dealloc方法中删除你的属性。

如果您使用ARC,您应该注意到某些操作可以保留您的控制器,并且在某些情况下永远不会被删除。注意方法,它采取代表对象,他们可能不会使用弱引用

看一看这款苹果article about memory management

你可以只使用在页头的方法autoreleasefor (UIView *view in [self.view subviews]) {view release};的dealloc

enter image description here

事实上释放是相反的操作以保持。如果确实保留,则在分配的内存中增加1个对象实例。发生在您致电alloc, copy, new, mutableCopy时。如果你使用ARC你不能释放对象,内存管理已经不是你的问题。

+0

感谢您的回应。在我的情况下,我使用弧,我想减少/避免我的应用程序中的内存压力。我想要的是紧急释放对象,因为我的应用程序消耗大量内存。 – janusbalatbat 2012-03-16 14:41:25