简体   繁体   中英

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. 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 !!!

It's been a while. This issue was caused because of references being retained.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM