在堆栈中释放viewcontroller(在didReceiveMemoryWarning之后)

时间:2013-04-12 12:09:04

标签: ios objective-c uiviewcontroller release didreceivememorywarning

我想删除堆栈中的所有viewcontrollers(Root除外)以在“内存警告”之后释放内存。

我在最后一个控制器中使用popToRootViewController。

处理: Root(推送) - > AController(推) - > BController(在记忆警告返回后) - >根

(在BController中)

- (void)didReceiveMemoryWarning {
    CMLog(@"BController");

    [super didReceiveMemoryWarning];

    CMLog(@"[allControllers lastObject]");
    [self.navigationController popToRootViewControllerAnimated:NO];
}

日志

  1. 收到内存警告。
  2. [RootViewController didReceiveMemoryWarning]
  3. [AController didReceiveMemoryWarning]
  4. [BController didReceiveMemoryWarning]
  5. [BController didReceiveMemoryWarning]:[allControllers lastObject]
  6. (popToRootViewControllerAnimated)
  7. 所以我重复这个过程

    1. 收到内存警告。
    2. [RootViewController didReceiveMemoryWarning]
    3. [AController didReceiveMemoryWarning]
    4. [BController didReceiveMemoryWarning]
    5. [AController didReceiveMemoryWarning](<<<< 重复
    6. [BController didReceiveMemoryWarning](<<<< 重复
    7. [BController didReceiveMemoryWarning]:[allControllers lastObject]
    8. (popToRootViewControllerAnimated)
    9. 经过多次尝试,应用程序崩溃,因为内存不足

      我可以简单地删除stack中的视图控制器吗?并将释放记忆?

0 个答案:

没有答案