をクラッシュさせるが、私はクラッシュを再現することはできません。私はいくつかの仮定しか持っていませんが、私は盲目的な修正をしたくありません。私はちょうど修正で納得したい:ARCリードは、私は時々、クライアント側でOSXシステム上でクラッシュしたコードの一部を持っているCoreFoundationのオブジェクト
+ (NSArray *)loginItems:(NSError *__autoreleasing *)error {
LSSharedFileListRef list = [self loginItemsFileListRef];
NSMutableArray *result = [NSMutableArray array];
NSArray *items = [self loginItemsForFileListRef:list];
CFRelease(list);
for (id item in items) {
LSSharedFileListItemRef itemRef = (__bridge LSSharedFileListItemRef)item;
[result addObject:[self loginItemFromItemRef:itemRef]];
}
return result;
}
+ (NSDictionary *)loginItemFromItemRef:(LSSharedFileListItemRef)itemRef {
NSMutableDictionary *itemDict = [NSMutableDictionary dictionary];
// Name
CFStringRef nameRef = LSSharedFileListItemCopyDisplayName(itemRef);
if (nameRef) {
NSString *name = (__bridge NSString *)nameRef;
itemDict[RESLoginItemsNameKey] = name.stringByDeletingPathExtension;
CFRelease(nameRef);
}
// Path
CFURLRef URLRef = NULL;
if (LSSharedFileListItemResolve(itemRef, 0, &URLRef, NULL) == noErr) {
if (URLRef) {
NSURL *URL = (__bridge NSURL *)URLRef;
NSString *path = URL.path;
if (path) {
itemDict[RESLoginItemsPathKey] = path;
}
CFRelease(URLRef);
}
}
// Hidden
CFBooleanRef hiddenRef = LSSharedFileListItemCopyProperty(itemRef,
kLSSharedFileListLoginItemHidden);
if (hiddenRef) {
if (hiddenRef == kCFBooleanTrue) {
itemDict[RESLoginItemsHiddenKey] = @YES;
}
CFRelease(hiddenRef);
}
return itemDict;
}
クラッシュloginItems内:つまりSharedFileListItemDeallocateは、クラッシュを引き起こす。 NSArrayのアイテムが自動リリースされたとき。私はそう思う:
SSharedFileListItemRef itemRef = (__bridge LSSharedFileListItemRef)item;
ARCの動作を壊し、ループが終了すると、配列の具体的な項目が解放されます。そして2回目のリリースはクラッシュする関数戻り時に呼び出されます。
は、誰もが私の考えを証明または反証することができていますか?ありがとう。
http://stackoverflow.com/questions/10590649/a-simple-code-that-worked-fine-under-gc-but-started-crashing-in-arcをチェックしますか – Shekhu