如果我收到内存警告,在哪里发布我的所有观点?
如果我收到内存警告,我必须释放我所有的观点和观点。数据 ?
我是否必须在
- (void)didReceiveMemoryWarning
或
- (void)viewDidUnload
中释放
If I am receiving memory warnings where exactly I have to release all my views & data ?
Whether I have to release in
- (void)didReceiveMemoryWarning
or in
- (void)viewDidUnload
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 iPhone OS 3.0 及更高版本,可能会在内存不足的情况下调用 viewDidUnload,因此最好在 viewDidUnload 中释放视图,请注意,对于自定义视图,请在 viewDidLoad 而不是类的 init 方法中创建它们。
didReceiveMemoryWarning
更多地用于释放自定义数据结构而不是释放视图。For iPhone OS 3.0 and later
viewDidUnload
maybe called during low memory situtations so best to release views in viewDidUnload, just note that for custom views, create them at viewDidLoad instead of init method of the class.didReceiveMemoryWarning
is used more for releasing custom data structures instead of releasing views.这应该只用在你不再需要的东西上,所以把绝对不必要的东西放在这里,例如,如果你不再使用视图并且它可能没有被释放,你可以在这里释放它,这样当内存警告出现时它将被释放。
在这里,您确保视图将被释放,以防视图控制器另外引用它们。你可以参考这个问题:何时使用viewDidUnload
This is supposed to be used only on things that you dont and wont need anymore so put here what is strictly innecessary, for instance if you are not using a view anymore and maybe it wasnt released you can release it here so when the memory warning comes it will be released.
Here you make sure that the views will be released in case they are referenced additionally by a view controller. You can refer to this question: When to use viewDidUnload