我有ABAddressBookGetPersonWithRecordID和ABPersonSetImageData的内存泄漏.在发布之前我一直在寻找解决方案,但我仍然不明白.如果我在iPhone 3GS上玩了很长时间,或者与iPhone 3G只有几个联系人,实际上应用程序崩溃了.这是我在didSelectRowAtIndexPath方法中的代码.我已经看到了使用这些方法的示例代码,但我看不到我缺少的内容.先感谢您.(抱歉错误...)
Contact *myContact = [fetchedResultsController objectAtIndexPath:indexPath];
cancelCreateContact = NO;
ABAddressBookRef ab = ABAddressBookCreate();
int len = ABAddressBookGetPersonCount(ab);
ABRecordID contactID;
ABRecordRef person;
BOOL alreadyExists = NO;
CFStringRef first, last;
for(int i = 1; i < (len + 1); i++)
{
person = ABAddressBookGetPersonWithRecordID(ab, (ABRecordID)i);
if(!person){
len++;
continue;
}
first = ABRecordCopyValue(person, kABPersonFirstNameProperty);
last = ABRecordCopyValue(person, kABPersonLastNameProperty);
if ([[(NSString*)first lowercaseString] isEqualToString:[myContact.firstname lowercaseString]] && [[(NSString*)last lowercaseString] isEqualToString:[myContact.lastname lowercaseString]]) {
alreadyExists = YES;
contactID = ABRecordGetRecordID(person);
break;
}
}
if (alreadyExists) { …Run Code Online (Sandbox Code Playgroud)