iPhone内存管理:无需清理和释放应用程序上保留的对象退出? [英] iPhone Memory Management: No Need to Clean Up and Release Retained Objects on App Quit?

查看:109
本文介绍了iPhone内存管理:无需清理和释放应用程序上保留的对象退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是真的吗?


当应用程序即将退出时,
不必清理内存
通过调用所有
保留的对象释放,因为iPhone
操作系统将回收它
分配给您的应用程序的内存,当您
启动它。这是更快,更安全的
比依赖于应用程序正确
自己清理。你可以
验证这一点,通过在应用程序
委托的
dealloc方法中调用
(或调试器断点)并看到它从未被调用。

When the app is about to quit, it's not necessary to clean up the memory by calling release on all your retained objects, because the iPhone OS will reclaim the memory it allocated for your app when you launched it. This is faster and safer than rely on the apps to correctly clean up after themselves. You can verify this by putting an NSLog call (or a debugger breakpoint) in the dealloc method of your application delegate and seeing it's never called.

所以,当应用程序是
即将退出时清理内容是无用的。此外,
你有非常有限的时间,在
操作系统擦除你的应用程序,所以不要浪费
它在清洁的东西。关注保存
您的游戏和任何其他相关的
的东西。

So, cleaning things up when the app is about to quit is useless. Moreover, you have very limited time before the OS wipes your app out, so don't waste it on cleaning things. Focus on saving your game and any other relevant stuff.

来源(cocos2d-iphone.org)

推荐答案

是的。报价文档


重要提示:当应用程序
终止时,对象可能不会发送
dealloc消息,因为进程的
内存被自动清除在
退出 - 它是更有效率只是
允许操作系统清理
资源比调用所有的
内存管理方法。这有
对如何实现
dealloc方法的影响 - 参见资源
管理。

Important: When an application terminates, objects may not be sent a dealloc message since the process’s memory is automatically cleared on exit—it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management methods. This has implications for how you implement a dealloc method—see "Resource Management."

这篇关于iPhone内存管理:无需清理和释放应用程序上保留的对象退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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