根据 Instruments 的说法,我的对象release
在这一行发送了一条消息:
[currentDefaults setObject:self.myArray forKey:@"storedArray"]
这会导致过度释放和崩溃。NSZombies 当 Profiled 发现这条线和保留计数问题时。
但为什么?合成的属性是这样的:
@property (nonatomic, copy) NSArray*myArray;
为什么顶部的行会导致保留计数发生变化?
这是崩溃后的回溯(上面提到的第 103 行是上面的行):
(lldb) bt
* thread #20: tid = 0x3103, 0x01e31276 CoreFoundation`CFRetain + 22, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x01e31276 CoreFoundation`CFRetain + 22
frame #1: 0x01eeca00 CoreFoundation`__CFDictionaryStandardRetainValue + 80
frame #2: 0x01e74e62 CoreFoundation`__CFBasicHashReplaceValue + 34
frame #3: 0x01e41964 CoreFoundation`CFBasicHashSetValue + 2628
frame #4: 0x01e40ee3 CoreFoundation`CFDictionarySetValue + 227
frame #5: 0x01e773b5 CoreFoundation`-[CFXPreferencesSource setValue:forKey:] + 85
frame #6: 0x01e8a81e CoreFoundation`-[CFXPreferencesPropertyListSource setValue:forKey:] + 110
frame #7: 0x01e8a72f CoreFoundation`_CFXPreferencesSetValue + 159
frame #8: 0x01e8a5b3 CoreFoundation`CFPreferencesSetAppValue + 51
frame #9: 0x01372ceb Foundation`-[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 100
frame #10: 0x00003922 Ivory Bull Charts`__21-[SavedData saveData]_block_invoke_0 + 178 at SavedData.m:103
frame #11: 0x017a3330 libdispatch.dylib`_dispatch_call_block_and_release + 15
frame #12: 0x017a4439 libdispatch.dylib`_dispatch_worker_thread2 + 302
frame #13: 0x996a3b24 libsystem_c.dylib`_pthread_wqthread + 346
(lldb)