ios - ABPersonCopyImageData 泄漏

标签 ios memory-leaks addressbook allocation

我在从 AddressBook 中获取图像时遇到了很大的问题,下面我粘贴了我的代码。此 imageData 从未被释放,在我的 Allocations Instruments 上它看起来总是在内存中它永远不会释放。

@autoreleasepool {
            CFDataRef imageData = ABPersonCopyImageData(record);
            if(imageData)
            {
                CFRetain(imageData);
                CFRelease(imageData);
                imageData = NULL;
                imageData = nil;
            }
        }

最佳答案

您过度保留了 imageData

CFDataRef imageData = ABPersonCopyImageData(record); // Returns a +1 owned object
if(imageData)
{
    CFRetain(imageData);     // This is now +2
    CFRelease(imageData);    // This is now +1
    imageData = NULL;        // You've lost the pointer that lets you release it
    imageData = nil;         // Does nothing.
}

将它放在自动释放池中不会执行任何操作,因为您没有任何自动释放的对象。

看看 Core Foundation Create Rule

关于ios - ABPersonCopyImageData 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17198294/

相关文章:

iphone - 在 iPhone 的数组中存储地址簿联系人

ios - 如何使用 NSSet 填充 tableView? ( swift )

javascript - Instagram iphone Hook

c++ - 内存泄漏 C++

objective-c - 帮助查找内存泄漏

iphone - 如何给 iPhone 联系人添加备注?

ios - UIScrollView 覆盖 NavigationBar

ios - 将 NS_OPTIONS 枚举 (UIRemoteNotificationType) 位掩码转换为 NSString 分隔值

memory - 当包含它的变量被重新分配时,分配会发生什么?

ios - 从 Swift 应用程序中的 native 应用程序访问最近通话列表