EXC_BAD_ACCESS when trying to issue ABRecordRef

I have the following class, which is a wrapper around 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 left some of the methods, but they are not relevant to this issue.

Everything works fine, except what I get EXC_BAD_ACCESSin line if(person) CFRelease(person);. Why is this happening? I do not call CFRelease or CFRetain anywhere in my application.

Edit, another note: if I add this right in front of the CFRelease line:

NSLog(@"retain count is %d", CFGetRetainCount(person));

He is typing retain count is 1

+3
source share
1 answer

I feel shy. I had the following code:

// getting the address
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, addressIndex);

NSString *_street = (NSString *)CFDictionaryGetValue(dict,
    kABPersonAddressStreetKey);
if(_street != nil) street = _street;    

-, CFDictionaryGetValue ... , , Copy . , CFRelease () , .

, . , .

+5

Source: https://habr.com/ru/post/1746629/


All Articles