退出应用程序时dealloc方法是否正常执行? [英] does dealloc method being executed normally when quitting the application?
问题描述
我使用如下代码(例如在我的 appController.m 中)在我的应用程序终止时进行一些清理......
I use code like the following (inside my appController.m for example) to do some cleanup when my application terminates...
- (void) dealloc {
[myObject release]; // myObject 's dealloc will not be called either !!!
[arraySMSs release];
[super dealloc];
}
当应用退出时这个方法永远不会被调用!为什么 ?有没有更好的地方来做我的清理工作?未被调用的事实解决了内存泄漏问题?还是操作系统负责清理?
This method never get called when the app quits! Why ? Is there a better place to do my clean up ? The fact that is not called addresses memory-leak issues ? Or the OS does take care of clean up ?
谢谢...
推荐答案
系统没有理由确保在应用程序终止时单独释放每个对象.
这样做只会浪费 CPU 周期和用户时间.
There is no reason for the system to ensure that every object is individually deallocated upon application termination.
Doing so is just a waste of CPU cycles and a waste of the user's time.
当应用终止时,系统会以完全自动且不可避免的方式回收该应用使用的所有资源.
When an app is terminated, all resources used by that app are reclaimed by the system in an entirely automatic and unavoidable fashion.
如果您需要在应用程序终止时发生某些事情,请使用应用程序委托的挂钩来执行此操作.但不要依赖那个.用户可以随意强制重启设备或强制退出应用程序.
If you need something to happen at app termination, use the application delegate's hooks for doing so. But don't rely on that. A user may force reboot a device or force quit an application at whim.
这篇关于退出应用程序时dealloc方法是否正常执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!