当呈现为模式视图控制器时,ARC UINavigationController 堆栈不会被释放
首先:我将我的应用程序移植到 ARC,一切似乎都正常。但现在我发现了一个问题:我有一个 UINavigationController,它以模态方式呈现,其堆栈上有一些 UIViewController。但是当我关闭模式视图控制器时,堆栈中的视图控制器似乎没有被释放。这就是我所做的:
UIViewController* root = [[UIViewController alloc] init];
UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:root];
[self presentModalViewController:navi animated:TRUE];
然后从根开始推送更多视图控制器,但这并不重要。事实是,当我稍后调用
[self dismissModalViewControllerAnimated:TRUE];
root 时,它并没有被释放。当然,在我的代码根中是 UIViewController 的子类,并且我跟踪 dealloc 和 viewDidUnload,但没有任何内容被调用。
有什么想法吗?
First: I ported my App to ARC and everything seemed to work. But now I discovered a problem: I have a UINavigationController that is presented modally with some UIViewControllers on its stack. But when I dismiss the modal view controller, the view controllers from the stack don't seem to be deallocated. Here is what I do:
UIViewController* root = [[UIViewController alloc] init];
UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:root];
[self presentModalViewController:navi animated:TRUE];
Then from the root I push some more view controllers, but that doesn't really matter. The fact is when I later call
[self dismissModalViewControllerAnimated:TRUE];
root doesn't get deallocated. Of course in my code root is a subclass of UIViewController, and I track dealloc and viewDidUnload, but nothing gets called.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的导航控制器里面有什么?罪魁祸首可能是其他东西(可能是导航控制器内的视图控制器),它导致了链的上游,这意味着导航控制器不会被释放。
无论哪种方式,您发布的代码都是正确的,因此如果您的导航控制器在调用
dismissModalViewController
后没有被释放,则表明其他东西仍然有对其或其依赖项之一的活动引用。我知道这不能回答您的问题,但您可能需要四处寻找。What's inside your navigation controller? It could be that something else (perhaps a view controller inside your navigation controller) is the culprit, which is leading up the chain meaning the navigation controller doesn't get released.
Either way, the code you posted is correct, so if your navigation controller isn't being released after calling
dismissModalViewController
it would suggest that something else still has an active reference to it or one of its dependencies. I know that doesn't answer your question, but you will probably have to hunt around.由于您没有显示实际代码,因此很难判断根视图控制器发生了什么。
但是,对于 ARC,如果你有一个指向对象的强指针,它就不会被释放。我怀疑您在将其添加到导航控制器后仍保留着该控制器。
但是,如果没有看到你的代码,我无法判断。
Since you aren't showing actual code, it's hard to tell what is going on with your root view controller.
But, with ARC, if you have a strong pointer to an object, it won't get released. I suspect that you are holding on to this controller after adding it to your navigation controller.
But, without seeing your code, I can't tell.