如何调试“发送到释放实例的消息"在 Xcode 4 中? [英] How to debug "message sent to deallocated instance" in Xcode 4?

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

问题描述

我按下 alt+cmd+r 并在参数中激活 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 保留计数消息.

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 静态分析器没有抱怨这个明显的故障.

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

推荐答案

如果再次出现这种情况,您可以运行专用的 Zombies 工具.按 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.

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

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