启用NSZombies,调试信息 [英] NSZombies enabled, debug information

查看:174
本文介绍了启用NSZombies,调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Mac应用在运行循环中因exc_bad_access崩溃. 因此,我启用了NSZombies,现在我没有看到预期的错误(因为未取消分配对象).

My Mac app is crashing with exc_bad_access on the run loops. So I enabled NSZombies, and Now I don't see such error as expected ( As the objects are not de-allocated).

但是,我在控制台中找不到任何有用的NSZombie Log. 有没有办法找出问题所在?

But, I don't find any useful NSZombie Log in the console. Is there a way to identify the issue ?

推荐答案

这具有挑战性.可可中此错误的最常见原因是直接访问您的ivars,而不是使用访问器.访问器使绝大多数内存崩溃消失了.

It's challenging. The most common cause of this error in Cocoa is directly accessing your ivars rather than using accessors. Accessors make the vast majority of memory crashes go away.

也就是说,它们不是内存错误的唯一原因.您可能以其他方式访问内存. NSZombie做一件事:当您取消分配对象时,NSZombie表示实际上不取消分配对象".相反,它将对象转换为僵尸对象,如果您向其发送消息,则会显示错误.但这仅在崩溃是由于向已取消分配的实例发送消息而导致崩溃时才有用.可能还有很多其他事情.

That said, they're not the only cause of memory errors. You may be accessing memory other ways. NSZombie does one specific thing: When you deallocate an object, NSZombie says "don't actually deallocate the object." Instead it turns the object into a zombie object that prints an error if you send it messages. But that only helps if the crash is due to sending a message to a deallocated instance. It could be lots of other things.

您应该首先从崩溃堆栈本身开始.查找堆栈,看看它可能是什么样的对象,或者是谁在调用它.

You should start first with the crash stack itself. Look up the stack and see what kind of object it might be, or who might be calling it.

阅读 TN2124 ,尤其是BSD部分内存分配器,以及启用Malloc调试功能内存使用情况性能指南"部分.您可以使用比NSZombie更低级别的工具. MallocScribble通常是最有用的.它用0x55覆盖释放的内存,这样您更有可能更快崩溃,并且更容易在调试器中检测释放的内存. MallocPreScribble对于查找未初始化的内存很有用,但这仅在您执行原始malloc调用时才真正有用. ObjC对象总是预先初始化的.

Read TN2124, particularly the section on the BSD Memory Allocator, and the Enabling the Malloc Debugging Features section of the memory Usage Performance Guidelines. There are lower-level tools than NSZombie that you can use. MallocScribble is often the most useful. It overwrites deallocated memory with 0x55 so that you're more likely to crash sooner, and to make it easier to detect deallocated memory in the debugger. MallocPreScribble is useful for finding uninitialized memory, but this really only helps if you do raw malloc calls. ObjC objects are always pre-initialized.

当然,您必须戴上侦探帽.您程序的哪些部分最可疑?您是否正在执行多线程工作(如果未正确锁定,可能会导致内存崩溃).

And of course you have to put on your detective hat. What parts of your program are most suspicious? Are you doing multi-threaded work (that can cause memory crashes if you don't lock correctly).

如果复制容易,那么您会发现它.如果只是偶尔发生,那好吧...有时我几个月来就一直在寻找类似的错误.有时候很难.

If it reproduces easily, then you'll figure it out. If it only happens occasionally, well... I've hunted bugs like that for many months sometimes. Sometimes it's just hard.

这篇关于启用NSZombies,调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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