iPhone开发人员-在didReceiveMemoryWarning中或每次 [英] iPhone dev - In didReceiveMemoryWarning or every time

查看:80
本文介绍了iPhone开发人员-在didReceiveMemoryWarning中或每次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多视图应用程序中,您认为让视图在内存紧缺的情况下自动卸载还是每次只分配一个View Controller更好,而当您切换视图时,新的视图是更好的做法吗?创建,删除旧的,添加新的,释放旧的.每次取消分配也意味着切换到新选项卡时会稍有延迟(非常微小).那你觉得呢?

In a multi-view application, do you think its better to let views automatically get unloaded in memory tight situations, or to actually only ever have one View Controller allocated at a time, and when you switch views, the new one is created, the old one removed, the new one adde d and the old one released. Deallocating every time also means that there is a slight delay when switching to a new tab (very slight). So What do you think?

此外,我对如何以及何时何地以及由谁(通过viewDidUnload)自动释放视图感到有些困惑.如果有人可以帮我澄清一下,谢谢.

Also, I'm a bit confused about how and when and where and by who views are released (through viewDidUnload) automatically. If someone could clarify that for me, thanks.

推荐答案

通常,除非必须(didReceiveMemoryWarning)否则否则不要卸载视图,否则这将是有意义的(类似于不太可能使用的登录表单之类的东西)再次).

In general, don't unload views unless you have to (didReceiveMemoryWarning) or it makes sense (something like a login form that's unlikely going to be used again).

您不能真正假设您拥有固定的内存量. iPhone的内存少于iPod touch. iPhone 3GS的内存比其他任何一个都要大.越狱的手机通常内存要少得多.

You can't really assume that you have a fixed amount of memory. iPhone's have less memory than iPod touches. iPhone 3GS's have more memory than either. Jail-broken handsets often have substantially less memory.

仅在需要时才释放视图,以使您的应用在3GS上更快地运行,并允许其在可用内存较少的情况下运行.

By only releasing views when you have to you're making your app run faster on the 3GS and allowing it to run when there's less memory available.

如果didReceiveMemoryWarning方法不可见,则释放该视图.以下是来自文档(v3.x)的信息:

The didReceiveMemoryWarning method releases the view if it is not visible. The following is from the documentation (v3.x):

此的默认实现 方法检查是否查看 控制器可以安全地释放其 看法.如果视图 本身没有监督,并且 可以从nib文件中重新加载 或使用自定义loadView方法.如果 可以释放视图,这种方法 释放它并调用 viewDidUnload方法.

The default implementation of this method checks to see if the view controller can safely release its view. This is possible if the view itself does not have a superview and can be reloaded either from a nib file or using a custom loadView method. If the view can be released, this method releases it and calls the viewDidUnload method.

显然,您还需要释放所有缓存的数据. SDK2.x没有viewDidUnload方法.

Obviously you also need to release any cached data. SDK2.x does not have the viewDidUnload method.

这篇关于iPhone开发人员-在didReceiveMemoryWarning中或每次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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