Use __bridge_transfer
instead and let ARC worry about it (or bits of it):
// Create an new address book object with data from address book database
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
// Returns all the records in address book and store in array
NSArray * allPeople = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
// Allocate memory for appdelegare mutable array to store contacts as dictinary object
appDelegate.allPeopleDict = [[NSMutableArray alloc]init];
for (id person in allPeople) {
// Get name of person from address book contacts
NSString * name = (__bridge_transfer NSString *)(ABRecordCopyCompositeName((__bridge ABRecordRef)(person)));
// Get phone numbers of person from address book contacts
ABMultiValueRef phones = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);
// Create a mutable array to store phone numbers
NSMutableArray * phoneNumbersArray = [[NSMutableArray alloc]init];
for (CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
// Get each phone number of a person
NSString * phoneNumber = (__bridge_transfer NSString *)(ABMultiValueCopyValueAtIndex(phones, i));
// Add the phone number to phone numbers array and trim the phone number
[phoneNumbersArray addObject:[self trimThePhoneNumber:phoneNumber]];
}
// Create a dictionary object with name and phonenumbers
NSDictionary * personDict = @{
name : phoneNumbersArray
};
CFRelease(phones);
// Add this dictionary object to mutable array
[appDelegate.allPeopleDict addObject:personDict];
}
CFRelease(addressBook);