如何调试“发送到解除分配的实例的消息”在Xcode4? [英] How to debug "message sent to deallocated instance" in Xcode4?

查看:135
本文介绍了如何调试“发送到解除分配的实例的消息”在Xcode4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按下了ALT + CMD + R并在Arguments> Environment Variables中激活了NSZombieEnabled。另外,我在诊断>内存管理>启用僵尸对象中激活了它。

I pressed ALT+CMD+R and activated NSZombieEnabled in Arguments > Environment Variables. Additionally, I activated it in Diagnostics > Memory Management > Enable Zombie Objects.

然而,当我构建并运行时,我的应用程序崩溃时给了我这个无用的消息控制台:

However, when I built and run, at some point my app crashes giving me this useless message in the console:

*** -[CALayer retainCount]: message sent to deallocated instance 0x656b260

堆栈跟踪同样没用。我将细节级滑块一直向右移动。线程1只是告诉我这个:

The stack trace is just as useless. I moved the details-level slider all the way to the right. Thread 1 simply shows me this:

一切都是系统所有,并且没有一行与我的应用程序相关。所以很明显NSZombiesEnabled不像它在Xcode 3中那样工作,它停在死对象上。

Everything is system-owned and there's not a single line related to my app. So obviously NSZombiesEnabled doesn't work as it did in Xcode 3, where it halted on the dead object.

有没有办法找出哪个 CALayer是否过早分配?

Is there any way to figure out which CALayer is deallocated too early?

更新:因此,在构建并运行大约100次之后突然问题消失了!它完全消失了!最好的部分:我没有以任何方式修改我的代码!在中间我用clean命令清理了build文件夹和项目几次,并在模拟器中删除了几次应用程序。

Update: So after building and running about 100 more times suddenly the problem DISAPPEARED! It's completely gone! And the best part: I did not modify my code in any way! Inbetween I cleaned the build folder and project with the clean commands several times and deleted the app in the Simulator several times as well.

更新2:幸运的是问题再次出现。而现在似乎持久。幸运的是,因为我更喜欢找到根本原因而不是随意烦扰用户。

Update 2: Fortunately the problem re-appeared. And now it seems persistent. Fortunately, because I prefer finding the root cause rather than annoying the users by random.

更新3:最后偶然发现:

Update 3: Finally found it by accident:

startButton = newBttn;

应该是:

self.startButton = newBttn;

startButton是一个保留属性,在-dealloc中我发布了它。因此它在大多数(但不是全部)情况下得到了过度释放,在视图逐渐消失之后崩溃,给出了奇怪的CALayer retainCount消息。

startButton was a retaining property and in -dealloc I released it. So it got overreleased and in most (but not all) cases after the view faded out it crashed giving that weird CALayer retainCount message.

Zombies Instrument(CMD + I)最后指出它与按钮有关。只是不知道为什么以及在哪里。

The Zombies Instrument (CMD + I) finally pointed out that it had to do with a button. Just didn't know why and where.

Clang Static Analyzer没有抱怨这个明显的故障。

Clang Static Analyzer didn't complain about this obvious glitch.

推荐答案

如果再次出现,您可以运行专用的僵尸乐器。按Command + I来分析应用程序并选择Zombies仪器(您必须在模拟器上运行)。如果你得到一个僵尸,你可以显示该对象的整个记忆历史(每个保留/释放),这对追踪错误非常有帮助。

If this crops up again, you can run a dedicated Zombies instrument. Hit Command+I to profile the app and select the Zombies instrument (you must be running on the simulator). If you get a zombie, you can display the entire memory history (each retain/release) for that object, which is immensely helpful in tracking down errors.

这篇关于如何调试“发送到解除分配的实例的消息”在Xcode4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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