AbaddressBookRef leaked in iOS

I am parsing the address book in iOS, but Leaks instrument reports a large amount of memory leaks, and I can’t seem to track down the problem

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];

Okay, this works, it won’t leak

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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 427 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.