iOS程序退出的时候不执行dealloc函数的疑惑

来源:互联网 发布:最知女人心 编辑:程序博客网 时间:2024/05/16 04:43

今天有人问为什么程序退出的时候没有执行appDelegate的dealloc函数,我测试了下是真的没有执行,疑惑了很久,后来在网上找到一位大牛的解释,分享给有同样疑惑的童鞋参考下。

 

“Regardless of how a process terminates, the same code in the kernel is eventually executed. This kernel code closes all the open descriptors for the process, releases the memory that it was using, and the like.”

如果是程序在调用exit系统调用退出的话整个process所占用的内存空间(heap, stack, and static等等)和此进程占用的文件句柄都交付给内核处理了,由内核来一并清理掉,所以这个时候就没需要单独来对每个对象来dealloc了。