1

我想在“内存警告”后删除堆栈中的所有视图控制器(Root 除外)以释放内存。

我在最后一个控制器中弹出ToRootViewController。

流程:Root(push)->AController(push)->BController(内存警告后返回)->Root

(在 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)

所以我重复这个过程

  1. 收到内存警告。
  2. [RootViewController didReceiveMemoryWarning]
  3. [AController didReceiveMemoryWarning]
  4. [BController didReceiveMemoryWarning]
  5. [AController didReceiveMemoryWarning](<<<<重复)
  6. [BController didReceiveMemoryWarning](<<<<重复)
  7. [BController didReceiveMemoryWarning]:[allControllers lastObject]
  8. (popToRootViewControllerAnimated)

多次尝试后应用程序崩溃,因为内存不足

我可以简单地删除堆栈中的视图控制器吗?并会释放内存?

4

0 回答 0