I’ve got the following class that is a wrapper around an 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
I’ve left some of the methods out, but they aren’t relevant to this question.
Everything works fine, except I get an EXC_BAD_ACCESS on the if(person) CFRelease(person); line. Why does this happen? I’m not calling CFRelease or CFRetain at all anywhere else in my app.
Edit, another note: If I add this right before the CFRelease line:
NSLog(@"retain count is %d", CFGetRetainCount(person));
It prints retain count is 1
I feel sheepish. I had the following code:
Apparently, CFDictionaryGetValue doesn’t make a copy… and that’s probably why it doesn’t have
Copyin the function name. I wasn’t retaining it, and so CFRelease(person) was causing street to be released after it was already reclaimed.I guess the rest of the code in the class was relevant. Sorry, I’ll try to not make this mistake when posting here in the future.