简体   繁体   English

为什么我的属性获取器会导致NSZombie错误?

[英]Why does my property getter cause an NSZombie error?

I have a service object called JSONNetworkUtility, and I store it in my model as an ivar, as well as a synthesized property with the same name, nonatomic and retained: 我有一个名为JSONNetworkUtility的服务对象,并将其作为模型存储在模型中,还具有一个具有相同名称,非原子性和保留名称的综合属性:

myNetworkUtility = [[JSONNetworkUtility alloc] initNetworkConnectionWithURL:urlString withQueryString:nil delegate:self];

The delegate includes two callbacks, one is networkUtility:didFailWithError: and the other is networkUtility:didFinishWithData: . 该委托包括两个回调,一个是networkUtility:didFailWithError: ,另一个是networkUtility:didFinishWithData: networkUtility:didFailWithError: The weird thing is that the property is causing some weird errors: 奇怪的是,该属性导致了一些奇怪的错误:

- (void)networkUtility:(JSONNetworkUtility *)networkUtility didFinishWithData:(NSArray *)jsonArray
{
    NSLog(@"myNetworkUtility = %@", myNetworkUtility);
    // returns <JSONNetworkUtility: 0x3944450>

    NSLog(@"networkUtility = %@", networkUtility);
    // also returns <JSONNetworkUtility: 0x3944450>

    NSLog(@"self.myNetworkUtility = %@", self.myNetworkUtility);
    // fails and throws an NSZombie error!
}

The error I get on that line is: 我在那条线上得到的错误是:

*** -[MyModel myNetworkUtility]: message sent to deallocated instance 0x148190 *** -[MyModel myNetworkUtility]:消息发送到已释放实例0x148190

I'm totally stumped! 我完全迷住了! Any clues as to why it's failing on a getter? 关于它为什么在吸气剂上失败的任何线索? And why is it returning a completely different object? 为什么返回一个完全不同的对象?

The reason I'm using a getter is because I wanted to use self.myNetworkUtility = nil so I can write over the top of the property with a new object, but I've cut it back to just this trace and I'm still having problems... 我使用吸气剂的原因是因为我想使用self.myNetworkUtility = nil所以我可以用新对象覆盖属性的顶部,但是我将其切回到了此迹线,但我仍然有问题...

Thanks! 谢谢!

I think the problem is that MyModel is deallocated. 我认为问题是MyModel被释放了。 When you're accessing the ivar, the objects are still there in that memory address address, the memory is not yet corrupted. 当您访问ivar时,对象仍在该内存地址中,内存尚未损坏。 But when sending a message to deallocated 'self' the runtime catches the fact that the object is deallocated. 但是,当发送消息给已释放的“自己”时,运行时会捕获到对象已被释放的事实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM