ConfusedNoob
ConfusedNoob

Reputation: 10196

Potential leak of an object - Call to function 'ABMultiValueCopyValueAtIndex' returns a Core Foundation object with a +1 retain count

I'm having this problem with the following address book code (that works great, but definitely leaks):

ABMultiValueRef email = ABRecordCopyValue(person, property);
NSString *type = (__bridge NSString *)(ABMultiValueCopyValueAtIndex(email, 0));
self.textEmail.text = type;
CFRelease(email);

I have already fixed one leak with the CFRelease(email) statement but can't fix this problem:

enter image description here

I can't call [type release] as this is an ARC project and CFRelease((CFTypeRef) type) isn't allowed. How can I release the bridged instance?

Upvotes: 1

Views: 912

Answers (2)

Soumya Ranjan
Soumya Ranjan

Reputation: 4843

Just add this method, instead of CFRelease(email);

if (email) { CFRelease(email); }

Upvotes: 2

Cocoanetics
Cocoanetics

Reputation: 8245

Change the __bridge to __bridge_transfer. This will make type be the owner of the reference and thus will be automatically released at end of scope.

Upvotes: 7

Related Questions