[英]ABPersonCopyImageDataWithFormat to CFDataRef causes memory growth/large memory footprint
CFData keeps growing as I copy contact images of 2000 contacts(all of them having a contact image) even though I am using a CFRelease after processing the data. 即使我在处理数据后使用CFRelease,但我复制2000个联系人的联系人图像(每个人都有一个联系人图像)时,CFData仍然保持增长。 I'm accessing one contact at a time to avoid a large memory footprint.
我一次访问一个联系人,以避免占用大量内存。 The code is provided below:
下面提供了代码:
- (void) getImageData:(ABRecordRef) contactPerson {
//Retrieving the contact photo
//base64 conversion from NSData to NSMutableString for the thumbnail image
@autoreleasepool {
if (ABPersonHasImageData(contactPerson)) {
//NSMutableData *contactImageData = [[NSMutableData alloc] init];
//NSMutableData *contactImageData = (CFBridgingRelease (ABPersonCopyImageDataWithFormat(contactPerson, kABPersonImageFormatThumbnail)));
CFDataRef contactImageData = ABPersonCopyImageDataWithFormat(contactPerson, kABPersonImageFormatThumbnail);
if (contactImageData) {
NSMutableString *imgData = [[NSMutableString alloc] init];
[imgData setString:[(__bridge NSData *)contactImageData base64EncodedStringWithOptions:0 ]];
currPhoneDBItem.photoBitmap = imgData;
imgData = nil;
//contactImageData = nil;
CFRelease(contactImageData);
}else{
NSLog(@"bitmap empty:");
currPhoneDBItem.photoBitmap = @"";
//CFRelease(contactImageData);
}
} else {
NSLog(@"bitmap empty:");
currPhoneDBItem.photoBitmap = @"";
}
}
}
CurrPhoneDBItem is a global object in the file. CurrPhoneDBItem是文件中的全局对象。 I am still trying to figure out how to fix this issue.
我仍在尝试找出解决此问题的方法。 Can't post the screen shot of the Instruments profile as I don't have the reputation required.
我没有所需的声誉,因此无法发布Instruments个人资料的屏幕截图。 But CFData ends up using 23MB.
但是CFData最终使用了23MB。 Any help will be greatly appreciated !!!
任何帮助将不胜感激 !!!
It's been a while. 有一阵子了。 This issue was caused because of references being retained.
引起此问题的原因是保留了引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.