objective-c - 使用 CFDictionaryRef 和 A​​BMutableMultiValueRef 的无法解释的泄漏

标签 objective-c cocoa cocoa-touch

以下代码创建了许多我不明白的泄漏,因为我释放了使用 Create 或 Copy 创建的所有对象。我没有广泛使用 CF 对象,因此我可能对保留周期有误解。如有任何帮助,我们将不胜感激:

ABMutableMultiValueRef webServices = ABRecordCopyValue(aRecord, kABPersonInstantMessageProperty);

    for (CFIndex i = 0; i < ABMultiValueGetCount(webServices); i++) { 

        CFDictionaryRef webService = CFDictionaryCreateCopy(NULL, ABMultiValueCopyValueAtIndex(webServices, i));

        webServiceLabel = ABMultiValueCopyLabelAtIndex(webServices, i);

        webServiceProvider = CFDictionaryGetValue(webService, kABPersonInstantMessageServiceKey);
        webServiceUserName = CFDictionaryGetValue(webService, kABPersonInstantMessageUsernameKey);

        // Data to be saved at this point
        if (webService) CFRelease(webService);
        if (webServiceLabel) CFRelease(webServiceLabel);
    }

    if (webServices) CFRelease(webServices);

最佳答案

这是你的问题:

CFDictionaryRef webService = CFDictionaryCreateCopy(NULL, ABMultiValueCopyValueAtIndex(webServices, i));

ABMultiValueCopyValueAtIndex 创建一个从未分配给变量的对象。它需要被释放,但从来没有被释放过。这是内存泄漏。

关于objective-c - 使用 CFDictionaryRef 和 A​​BMutableMultiValueRef 的无法解释的泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1612829/

相关文章:

ios - 带分页的 ScrollView

ios - UIView无限360度旋转动画?

objective-c - 保护关键代码不被再次调用

objective-c - NSURLConnection 奇怪的崩溃

ios - TWTRLogInButton - NSURLErrorDomain 错误 -1012

objective-c - 比较 Cocoa 中的字符串

c++ - 在我的 MacOS 应用程序中禁用 "Show Help Menu"快捷方式

ios - 使用 insertRowAtIndexPath 调整 UITableViewCell 高度

cocoa-touch - os x 相当于ios的rootViewController

iphone - 核心数据和核心位置