0
更新大約20個圖像聯繫人後,出現內存不足警告。我已經放置了代碼。誰能告訴可能是什麼原因?使用API的內存不足警告:ABPersonSetImageData
NSString *imagepath = [[IDLFactory documentsDirectoryPath] stringByAppendingFormat:@"/%@",value];
NSData *dataRef = [[NSData alloc] initWithContentsOfFile:imagepath];
CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
[dataRef release];
dataRef = nil;
CFErrorRef error;
ABPersonRemoveImageData(inContact, &error); // <-- clean any image first from ref
BOOL ret = ABPersonSetImageData(inContact, cfdata, &error);
if (ret)
{
ret = ABAddressBookSave(inAddressBook, &error);
} else
{
NSLog(@"Could not write the image to the person");
}
CFRelease(cfdata);
在此先感謝
- 如果存在任何圖像,ABPersonRemoveImageData()將被移除,否則它將返回FALSE作爲返回值。它不會填充新的數據。 - 我沒有使用任何autorelease對象在這裏使用autoreleasePool。無論如何,我在我調用此片段的方法中使用autoreleasePool。 – Manjunath 2010-11-24 04:35:02