peoplePicker内存使用ARC泄漏



我在项目中使用ARC,并收到以下潜在内存泄漏的警告(请参见注释行)。不知道如何处理。

-( 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

如有任何建议,我们将不胜感激。

提前谢谢。

ARC只管理Objective-C对象的内存,因此ABRecordCopyValue返回的phoneProperty(方法中的Copy表示它已被保留)需要由您的应用程序使用CFRelease发布。

无论是否使用ARC,您都必须自己处理CFMemory。离开前添加以下代码:

if (phoneProperty){
CFRelease(phoneProperty);
}

最新更新