【问题标题】:How to debug retain count using ARC?如何使用 ARC 调试保留计数?
【发布时间】:2012-11-14 19:48:37
【问题描述】:

我在我的 iPhone 应用程序上使用了 ARC,我试图捕捉一个错误,它给我以下输出(NSZombieEnabled, MallocStackLogging and guard malloc):

*** -[MyCustomClass retain]: message sent to deallocated instance 0x534e00

如何使用 ARC 跟踪保留计数?我应该如何使用带有instance 0x534e00 的 LLDB 控制台(当然会出现任何其他实例)来找到释放的实例?

郑重声明:我的代码中没有使用任何retain

谢谢!

【问题讨论】:

  • 使用 Instrument 的“僵尸”工具?
  • 如果您使用 ARC,为什么会向您的自定义类发送保留消息?但是,您应该使用 __strong 限定符将其更改为强引用。
  • 我没有使用retain,但是很强大。这就是我被这条消息绊倒的原因。
  • 在使用 ARC 时不要使用显式调用。使用 ARC 时不能调用保留、复制、可变复制、自动释放或释放。因此,删除语句 [MyCustomClass retain]。
  • 查看本教程以了解如何使用 Zombies 仪器:markj.net/iphone-memory-debug-nszombie

标签: iphone objective-c ios cocoa-touch automatic-ref-counting


【解决方案1】:

这并不意味着您明确写了[MyCustomClass retain]。系统正在为你做这件事。您应该使用 Zombies and Instruments 并尝试跟踪问题。至少你知道问题出在MyCustomClass,它缩小了范围。

【讨论】:

  • 我读到 NSZombiesEnabled 不能在 iPhone 上运行,而只能在 Simulador 中运行。如何使用 Instruments 工具在模拟器上为应用加注星标?谢谢。
【解决方案2】:

您的选择是:1. 不使用 ARC,或 2. 使用 ARC。但你不能两者都做。使用 ARC 时不能使用非 ARC 保留函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-14
    • 2014-03-28
    • 2013-01-23
    • 2013-02-21
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多