didReceiveMemoryWarning

didReceiveMemoryWarning

本文介绍了iOS 6 - viewDidUnload迁移到didReceiveMemoryWarning?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,从iOS 6开始, viewDidUnload 已弃用,我现在需要做什么?

So with viewDidUnload deprecated as of iOS 6, what do I need to do now?

删除它,并在 didReceiveMemoryWarning 中迁移所有内容,或者保留它,并且在 didReceiveMemoryWarning 中不做任何事情?

Delete it, and migrate all of it's contents in didReceiveMemoryWarning, or leave it, and don't do anything in didReceiveMemoryWarning?

推荐答案

简短的回答是,在很多情况下,你不需要改变任何东西。并且,您肯定想要将 viewDidUnload 的所有内容迁移到 didReceiveMemoryWarning

The short answer is that, in many cases, you don't need to change anything. And, you most certainly do not want to simply migrate all of the contents of viewDidUnload to didReceiveMemoryWarning.

一般来说,我们大多数人都会设置 IBOutlet nil in viewDidUnload (很大程度上是因为Interface Builder会把它放在那里)并做一般的内存释放(例如清除缓存,释放易于重建的模型数据) ,等等) didReceiveMemoryWarning 。如果这是你的方式,那么你可能不需要任何代码更改。

Generally, most of us do the setting of IBOutlet references to nil in viewDidUnload (largely because Interface Builder would put that there for us) and do the general freeing of memory (e.g. clearing of caches, releasing of easily recreated model data, etc.) in didReceiveMemoryWarning. If that's the way you do it, then you probably don't require any code changes.

根据iOS 6 viewDidUnload 文档:

According to the iOS 6 viewDidUnload documentation:

因此,您想要移动 IBOutlet的设置在任何地方引用 nil ,因为视图不再被清除。在 didReceiveMemoryWarning 或类似的东西中将它们设置为 nil 是没有意义的。

Therefore, you do not want to move the setting of your IBOutlet references to nil anywhere, because the views are no longer purged. It would make no sense to set them to nil in didReceiveMemoryWarning or anything like that.

但是,如果您通过在 viewDidUnload 中释放容易重新创建的模型对象,清空缓存等来响应低内存事件,那么东西应该肯定转移到 didReceiveMemoryWarning 。但是,我们大多数人已经在那里已经有了它。

But, if you were responding to low memory events by releasing easily-recreated model objects, emptying caches, etc., in viewDidUnload, then that stuff should definitely move to didReceiveMemoryWarning. But then, again, most of us already had it there already.

最后,如果你在中取消任何东西didReceiveMemoryWarning ,只是确保你的代码不再依赖于在你回弹时再次在 viewDidLoad 中重新创建它们,因为它不会被调用(因为视图本身从来就不是卸载)。

Finally, if you free anything in didReceiveMemoryWarning, just make sure your code doesn't rely upon them being recreated in viewDidLoad again when you pop back, because that will not be called (since the view, itself, was never unloaded).

正如applefreak所说,这取决于你在 viewDidUnload 中做了什么。如果您使用 viewDidUnload 中的显式示例更新您的问题,我们可能会提供较少的抽象忠告。

As applefreak says, it depends upon what you were doing in viewDidUnload. If you update your question with explicit examples of what you had in your viewDidUnload, we can probably provide less abstract counsel.

这篇关于iOS 6 - viewDidUnload迁移到didReceiveMemoryWarning?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 04:00