UIViewController卸载过程(ios6.0以后)

  在ios6.0以后,废除了viewWillUnload方法和viewDidUnload方法。

  在ios6以后,当收到didReceiveMemoryWarning消息调用之后,程序会自动调用didReceiveMemoryWarning函数,重写父类的- (void)didReceiveMemoryWarning函数:

 1 - (void)didReceiveMemoryWarning
 2 {
 3     [super didReceiveMemoryWarning];
 4     
 5     //拿到应用程序的窗口
 6     if ([self.view window] == nil) {
 7         //释放视图拥有的强引用view实例
 8         //......如:self.subView = nil;
 9         self.view = nil;
10     }  
11 }

在ios6.0之前,自动会释放UIViewController实例的根视图view,但是6.0之后,需要手动释放没有显示的控制器的view。也可以在里面释放大量的图片数据。

重写dealloc方法,执行最后的清理工作,注:其它属性会自动释放,不需要手动释放。

原文地址:https://www.cnblogs.com/hereiam/p/3788461.html