【问题标题】:Objective-C: use isa property to determine if variable has been deallocatedObjective-C:使用 isa 属性来确定变量是否已被释放
【发布时间】:2012-10-10 16:28:50
【问题描述】:

我有一个问题,变量被随机释放或损坏,我得到一个 NSInvalidArgumentException。它并不总是发生,但我能够在几次尝试后重现该问题。

我尝试了几种方法来检查属性是否是正确的类型,但都没有成功。

这是一切正常时的变量

这是应用崩溃时的变量

我注意到“isa = (Class)”部分现在返回错误而不是“CLLocation”,所以我正在尝试检查它,但它受到保护。

[fromPoint->isa isKindOfClass:[CLLocation class]]

我已经在这里尝试了答案,但我仍然遇到异常。

Objective c isKindOfClass missunderstanding?

isa pointer in objective-c

谢谢!

【问题讨论】:

    标签: objective-c ios


    【解决方案1】:

    看起来您有对已释放对象的引用。尝试使用NSZombieEnabled=YES 运行调试器。通过打开 Product>Edit Scheme... 并在运行配置的“环境变量”中添加一行来设置它。

    【讨论】:

    • 同时在你的调试方案中打开Diagostics > Memory Management下的一些选项来追踪潜在的内存问题。
    • Krumelur 说了什么;崩溃是一种症状,您尝试验证 isa 是为了解决这种症状。这样做不会修复实际的错误。
    • 感谢您的快速回复。我认为错误在于 fromPoint 被设置为指针引用:fromPoint = locationController.currentLocation; 我已将其更改为:fromPoint = [[CLLocation alloc] initWithLatitude:locationController.currentLocation.coordinate.latitude longitude:locationController.currentLocation.coordinate.longitude]; 我认为 locationController.currentLocation 正在被释放导致错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    相关资源
    最近更新 更多