people使用ARC进行内存泄漏

时间:2012-01-06 05:51:50

标签: ios automatic-ref-counting abrecord

我在我的项目中使用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

任何建议都将受到赞赏。

提前致谢。

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

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

if (phoneProperty){
CFRelease(phoneProperty);
}