I cannot seem to structure this method so that when I analyse the project it doesn’t complain.
It is complaining about how I release people object.
- (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];
}
And modify the CFRelease() before the return statement to be like this,