退出应用程序时,dealloc方法是否正常执行? [英] does dealloc method being executed normally when quitting the application?

查看:104
本文介绍了退出应用程序时,dealloc方法是否正常执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序终止时,我使用如下代码(例如在我的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屋!

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