什么是僵尸,是什么原因造成的?有僵尸进程和僵尸对象吗? [英] What are Zombies and what causes them? Are there Zombie processes and Zombie objects?

查看:205
本文介绍了什么是僵尸,是什么原因造成的?有僵尸进程和僵尸对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以找到有关僵尸的问题,但是没有一个问题可以直接解决它们是什么以及它们为什么以及如何发生的问题.有几个人在回答特定问题时解决了僵尸进程的问题,但没有解决原因.

I can find questions about zombies but none that directly addresses what they are and why and how they occur. There are a couple that address what zombie processes are in the context of answering a specific question but don't address the cause.

还有关于僵尸进程的问题以及与Objective-C/Cocoa相关的僵尸对象的问题.有什么区别或这些之间有何关系? Mac/iPhone上的"EXEC_BAD_ACCESS"(或其他平台上的类似错误)是否与僵尸同义?

There are also questions regarding zombie processes and questions about Objective-C/Cocoa-related zombie objects. What are the differences or how are these related? Is an "EXEC_BAD_ACCESS" on Mac/iPhone (or similar error on other platforms) synonymous with a zombie?

如何防止僵尸,并且有什么最佳实践可以帮助避免它们?

How can one prevent zombies and are there any best practices that will help avoid them?

将这些信息放在一个地方会很有帮助.如果可能,此问题旨在与平台/语言无关.

It would be helpful to have this information in one place. This question is intended to be platform/language agnostic, if possible.

推荐答案

僵尸进程和僵尸对象是完全无关的.僵尸进程是指父进程启动子进程而子进程结束,但父进程未获取子进程的退出代码的情况.流程对象必须一直呆到这种情况发生-它不消耗资源并且已经死亡,但它仍然存在-因此,就是僵尸".

Zombie processes and zombie objects are totally unrelated. Zombie processes are when a parent starts a child process and the child process ends, but the parent doesn't pick up the child's exit code. The process object has to stay around until this happens - it consumes no resources and is dead, but it still exists - hence, 'zombie'.

Zombie 对象是Cocoa/CoreFoundation的调试功能,可帮助您捕获内存错误-通常,当对象的refcount降至零时,它会立即释放,但这使调试变得困难.相反,如果启用了僵尸对象,则不会立即释放该对象的内存,而是将其标记为僵尸,并且将记录使用该对象的任何进一步尝试,并且您可以跟踪对象在其生命周期内在代码中的何处使用.

Zombie objects are a debugging feature of Cocoa / CoreFoundation to help you catch memory errors - normally when an object's refcount drops to zero it's freed immediately, but that makes debugging difficult. Instead, if zombie objects are enabled, the object's memory isn't instantly freed, it's just marked as a zombie, and any further attempts to use it will be logged and you can track down where in the code the object was used past its lifetime.

EXEC_BAD_ACCESS是您的常规您使用了错误的指针"异常,就像我那样:

EXEC_BAD_ACCESS is your run-of-the-mill "You used a bad pointer" exception, like if I did:

(*(0x42)) = 5;

这篇关于什么是僵尸,是什么原因造成的?有僵尸进程和僵尸对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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