Reputation: 113
I am using ARC in my project and am being warned of a potential memory leak (see commented lines) on the following. Not sure how to handle it.
-( BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property);
// Call to function 'ABRecordCopyValue' returns a Core Foundation object with a +1 retain count
int idx = ABMultiValueGetIndexForIdentifier (phoneProperty, identifier);
emailToValue= (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,idx);
// Object Leaked: object allocated and stored into 'phoneProperty' is not referenced later in this execution path and has a retain count of +1
Any advice would be appreciated.
Thanks in advance.
Upvotes: 0
Views: 833
Reputation: 56
No matter if the ARC is used, you both have to handle the CFMemory yourself. Add the code below before leaving:
if (phoneProperty){
CFRelease(phoneProperty);
}
Upvotes: 2
Reputation: 2759
ARC only manages memory for Objective-C objects, so phoneProperty
returned by ABRecordCopyValue
(The Copy
in the method indicates that it has been retained) needs to be released by your app using CFRelease
.
Upvotes: 3