iPhone - 什么时候是一个叫做viewcontroller的dealloc? [英] iPhone - when is dealloc for a viewcontroller called?

查看:79
本文介绍了iPhone - 什么时候是一个叫做viewcontroller的dealloc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UINavigationController在视图之间移动。当我在视图中来回移动时,我的应用程序使用的内存不断增加。在所有viewcontrollers的dealloc方法中放置NSLog语句时,我注意到它只被调用了一些viewcontrollers而不是所有被弹出的。

I am using UINavigationController to move between views. When I move back and forth in views, the memory used by my app keeps on increasing. On placing NSLog statements in the dealloc method of all viewcontrollers, I noticed it was being called for only some viewcontrollers and not all that were popped.

例如,这是推送视图的顺序MainViewController - > viewcontroller1 - > viewcontroller2 - > viewcontroller3

For instance, this is the sequence in which views are pushed MainViewController -> viewcontroller1 -> viewcontroller2 -> viewcontroller3

现在在viewcontroller3中,如果我执行popToViewController:mainController,则仅为viewcontroller3调用dealloc。它不是为viewcontroller1和2调用的。

Now in viewcontroller3 if I do a popToViewController:mainController, dealloc is called only for viewcontroller3. It is not called for viewcontroller1 and 2.

有人可以告诉我为什么会发生这种情况。

Can someone please tell me why this is happening.

<强>发现问题。如果viewcontroller保存的任何引用仍在内存中,则不会调用dealloc方法。在我的例子中,它是未在viewcontroller1和viewcontroller2中发布的MPMoviePlayerController对象。

推荐答案

这是一个案例最后一次,先关闭。因此,如果你想象你的第一个视图控制器是一个汉堡的底部发髻,你然后添加汉堡(第二个视图控制器),然后添加顶级汉堡(第三个视图控制器)。

It is a case of last on, first off. So if you imagine your first view controller is the bottom bun of a burger, you then add the burger (second view controller) and then the top burger (third view controller).

如果你回到汉堡你取下顶层面包(popViewController:调用弹出的视图的dealloc方法)。如果你想回到底部发髻然后你必须弹出汉堡(每次弹出视图时都会调用dealloc)。

If you go back to the burger you take off the top bun (popViewController: calls the dealloc method of the view that is popped). If you want to go back to the bottom bun then you have to pop the burger (dealloc is called every time the view is popped).

不确定为什么要弹出root第二个视图控制器的dealloc虽然不会被调用..

not sure why on pop to root the second view controller's dealloc wouldn't be called though..

hmm

这篇关于iPhone - 什么时候是一个叫做viewcontroller的dealloc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆