0

我有这个代码:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)personRecord
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    //TODO: release phoneNumberProperty when done
    ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(personRecord, kABPersonPhoneProperty);
    int selectedPhNum = ABMultiValueGetIndexForIdentifier(phoneNumberProperty, identifier);//Turns identifier into index
    NSString *txtNum = (NSString *)CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneNumberProperty, selectedPhNum));
    //NSLog(@"Selected ph num = %@", txtNum);
    [[self toTextField] setText:txtNum];
    phoneNumberProperty = nil;
    [self dismissViewControllerAnimated:YES completion:NULL];

静态分析仪说有潜在的泄漏。我知道我需要释放 phoneNumberProperty 但如何?我正在使用 ARC,所以 [phoneNumberProperty release] 不起作用。将其设置为零,它仍然会抱怨。

谢谢您的帮助

4

1 回答 1

2

使用 CFRelease 函数释放您的 ABMultiValueRef 变量:

...
if (phoneNumberProperty)
    CFRelease(phoneNumberProperty);
于 2012-09-28T15:34:09.353 回答