ios - 使用 ABRecord 和 ARC 的潜在泄漏

标签 ios memory-leaks ios6 clang-static-analyzer

我有这个代码:

- (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] 无法正常工作。将它设置为零,它仍然会提示。

感谢帮助

最佳答案

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

...
if (phoneNumberProperty)
    CFRelease(phoneNumberProperty);

关于ios - 使用 ABRecord 和 ARC 的潜在泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12642892/

相关文章:

ios - 设置水平 UIScrollView 的起点

c++ - 内存泄漏 : unable to break on a memory allocation number

iphone - 是否可以从 UITextField 自定义键盘?

ios - AVAudioEngine 录制 AVAudioPlayerNode 中播放的声音

javascript - jQuery Mobile 在页面转换之前阻止滚动到顶部?

ios - Appcelerator IOS模块开发

memory-leaks - 如何分析 Java 8 压缩类空间中的内存泄漏?

c++ - 为什么这段代码在 C++ 中有内存泄漏

iphone - 使用 UIPrintInteractionController 打印 PDF ios 5 有效,但在 ios 6 中不起作用并使我的应用程序崩溃

ios - 在 ios 中检测 sim 卡检测的可能方法?