【发布时间】:2010-05-21 21:11:29
【问题描述】:
我有以下类是 ABPerson (ABRecordRef) 的包装器:
@interface Recipient : NSObject {
ABRecordRef person;
}
- (id)initWithPerson:(ABRecordRef)person;
@end
@implementation
- (id)initWithPerson:(ABRecordRef)_person {
if(self = [super init]) person = CFRetain(_person);
return self;
}
- (void)dealloc {
if(person) CFRelease(person);
[super dealloc];
}
@end
我遗漏了一些方法,但它们与这个问题无关。
一切正常,除了我在if(person) CFRelease(person); 行上得到一个EXC_BAD_ACCESS。为什么会这样?我不会在我的应用程序的其他任何地方调用 CFRelease 或 CFRetain。
编辑,另一个注释:如果我在 CFRelease 行之前添加这个:
NSLog(@"retain count is %d", CFGetRetainCount(person));
它打印retain count is 1
【问题讨论】:
-
ABRecordRef
person对象是否有可能在调用 CFRelease 之前有一些内部对象被取消引用?? -
有可能,但我看过了,我想不出它会在哪里。
-
嗯,我可以看到该代码没有任何问题,所以要么你正在用其他方法做某事,要么贾斯汀有答案
标签: iphone cocoa core-foundation