First, I created the address Book.
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
This is what I suspect is a leak, but ABAddressBookRef and CFArrayRef are automatically released, right?
The rest of my code is below..
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *List = [[NSMutableArray alloc] init];
for (int i = 0; i
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i) ;
NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(ref)];
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty) ;
CFDataRef imgData = ABPersonCopyImageData(ref);
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
multi = ABRecordCopyValue(ref,kABPersonEmailProperty);
for (CFIndex i = 0; i
CFStringRef email, emailLabel;
emailLabel = ABMul tiValueCopyLabelAtIndex(multi, i);
email = ABMultiValueCopyValueAtIndex(multi, i);
NSString *emails = [NSString stringWithFormat: @"%@", (NSString *)email];
< br /> if (emails)
{
NSMutableDictionary *addDict = [[NSMutableDictionary alloc] init];
[addDict addObject:emails forKey:@"email"];
[ List addObject:addDict];
[addDict release];
}
CFRelease(email);
CFRelease(emailLabel);
}
if (firstName) {
CFRelease(firstName);
}
if (lastName) {
CFRelease (lastName);
}
if (imgData) {
CFRelease(imgData);
}
if (ref) {< br /> CFReleas e(ref);
}
CFRelease(multi);
}
//do something with list
[List release];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);NSMutableArray *List = [[NSMutableArray alloc] init]; for (int x = 0; x
I am parsing the address book in iOS, but Leaks instrument reports There are a lot of memory leaks and I can't seem to track down the problem
First, I created the address book.
ABAddressBookRef addressBook = ABAddressBookCreate();< br />CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
I suspect this is a leak, but ABAddressBookRef and CFArrayRef are automatically released, right?
The rest of my code is below..
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *List = [[NSMutableArray alloc] init];
for (int i = 0; i
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i) ;
NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(ref)];
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty) ;
CFDataRef imgData = ABPersonCopyImageData(ref);
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
multi = ABRecordCopyValue(ref,kABPersonEmailProperty);
for (CFIndex i = 0; i
CFStringRef email, emailLabel;
emailLabel = ABMultiV alueCopyLabelAtIndex(multi, i);
email = ABMultiValueCopyValueAtIndex(multi, i);
NSString *emails = [NSString stringWithFormat: @"%@", (NSString *)email];
< br /> if (emails)
{
NSMutableDictionary *addDict = [[NSMutableDictionary alloc] init];
[addDict addObject:emails forKey:@"email"];
[ List addObject:addDict];
[addDict release];
}
CFRelease(email);
CFRelease(emailLabel);
}
if (firstName) {
CFRelease(firstName);
}
if (lastName) {
CFRelease (lastName);
}
if (imgData) {
CFRelease(imgData);
}
if (ref) {< br /> CFRelease(r ef);
}
CFRelease(multi);
}
//do something with list
[List release];
Ok, this works and will not leak
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);NSMutableArray *List = [[NSMutableArray alloc] init]; for (int x = 0; x