[英]NSDictionaryM setObject:forKey: EXC_BAD_ACCESS crash
Crashlog: 崩溃日志:
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x12121212
libobjc.A.dylib - objc_msgSend - isEqual:
CoreFoundation - -[__NSDictionaryM setObject:forKey:]
Code: 码:
if (object) {
[_objects setObject:object forKey:key];
}
When init of _objects happens earlier in code: 当_objects的初始化发生在代码的前面时:
- (id)init {
self = [super init];
if (self) {
_objects = [[NSMutableDictionary alloc] init];
}
return self;
}
Object can be nil value, thats why I'm checking if it exist: 对象可以是nil值,这就是为什么我要检查它是否存在:
AFHTTPRequestOperation *object = [[AFHTTPRequestOperation alloc] initWithRequest:request];
I'm not sure what exactly can cause it. 我不确定到底是什么原因引起的。 Crash happens very rarely, I'm unable to reproduce it, however a few users got it. 崩溃很少发生,我无法重现,但是一些用户知道了。 I assume something got deallocated, could it be that _objects
is nil? 我假设某些东西被释放了,是否_objects
为nil? Or whole controller got deallocated? 还是整个控制器都被释放了? Why I can see isEqual
in the log? 为什么我可以在日志中看到isEqual
?
Can this fix the issue? 这可以解决问题吗?
if (object && _objects) {
[_objects setObject:object forKey:key];
}
You have checked not null condition for the dictionary and object value. 您已检查字典和对象值的条件是否为空。 Try to check nil condition for your key of object. 尝试检查您的对象密钥的无条件。 There might be a case where key can be nil. 在某些情况下,键可以为零。
if (object && _objects && key) {
[_objects setObject:object forKey:key];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.