我似乎无法构建此方法,因此当我分析项目时,它不会抱怨。
抱怨我如何发布人物对象。
- (NSArray *)getAllContacts {
NSMutableArray *result = [NSMutableArray array];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFRelease(addressBook);
NSArray *peopleArray = (NSArray *)people;
// Return if there are no contacts in the address book
if (peopleArray && peopleArray.count > 0) {
for (int i = 0; i <= peopleArray.count -1; i++) {
ABRecordRef person = [peopleArray objectAtIndex:i];
ABRecordID sourceID = ABRecordGetRecordID(person);
TableViewControllerItem *item = [AddressBookModel createTableViewControllerItemFromABRecordID:[NSString stringWithFormat:@"%i", sourceID]];
[result addObject:item];
}
CFRelease(people); //If I put the release here I get a potential leak of people
}
CFRelease(people); //If I put the release here I get a null pointer argument in call to CFRelease
return [NSArray arrayWithArray:result];
}
答案 0 :(得分:8)
// Remove the CFRelease() inside the if-block
在 return 语句之前修改 CFRelease()就像这样,
if (peopleArray) CFRelease(people);
return [NSArray arrayWithArray:result];