Reputation: 45
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. 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. 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. But CFData ends up using 23MB. Any help will be greatly appreciated !!!
Upvotes: 1
Views: 156
Reputation: 45
It's been a while. This issue was caused because of references being retained.
Upvotes: 1