ビルドと分析を使用すると、リークが発生しました(オブジェクトの潜在的なリークとして示されました)。それを修正するには以下を含むFixオブジェクトの潜在的なリーク
if (aContactfirstName){
CFRelease(aContactfirstName);
}
if (aContactLastName){
CFRelease(aContactLastName);
}
私のアプリはクラッシュします。
だから、plsはどこに漏れてそれを解決するか教えてくれます。
-(NSString*)getContactNameByPhoneNo:(NSString*)phoneNO{
NSString *aContactName = phoneNO;
ABAddressBookRef addressbook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressbook);
CFIndex numPeople = ABAddressBookGetPersonCount(addressbook);
for (int i=0; i < numPeople; i++) {
ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i);
ABMutableMultiValueRef phonelist = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex numPhones = ABMultiValueGetCount(phonelist);
for (int j=0; j < numPhones; j++) {
CFTypeRef ABphone = ABMultiValueCopyValueAtIndex(phonelist, j);
NSString *personPhone = (NSString *)ABphone;
NSLog(@"i am:");
personPhone =[personPhone stringByReplacingOccurrencesOfString:@"-"withString:@""];
personPhone=[personPhone stringByReplacingOccurrencesOfString:@")"withString:@""];
personPhone=[personPhone stringByReplacingOccurrencesOfString:@" "withString:@""];
personPhone=[personPhone stringByReplacingOccurrencesOfString:@"("withString:@""];
personPhone=[personPhone stringByReplacingOccurrencesOfString:@"+"withString:@""];
NSLog(@"xcxcxcxc");
CFRelease(ABphone);
if ([personPhone isEqualToString:phoneNO]){
NSString *aContactfirstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) ;
NSString *aContactLastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) ;
if (aContactLastName != NULL && aContactfirstName != NULL){
aContactName = [NSString stringWithFormat:@"%@ %@",aContactfirstName,aContactLastName];
}
else if(aContactfirstName != NULL){
aContactName = aContactfirstName;
}
else if(aContactLastName != NULL){
aContactName = aContactLastName;
}
if (aContactfirstName){
CFRelease(aContactfirstName);
}
if (aContactLastName){
CFRelease(aContactLastName);
}
break;
}
}
CFRelease(phonelist);
}
CFRelease(allPeople);
CFRelease(addressbook);
return aContactName;
}
どうもありがとうを返します – user198725878