smithms
smithms

Reputation: 113

peoplePicker memory leak using ARC

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

Answers (2)

waterforest
waterforest

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

Sherman Lo
Sherman Lo

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

Related Questions