memory management: am i doing something wrong here?
- by z s
Hi,
In a very small number of cases in my iphone app, I get a crash after the for loop in the code below:
ABAddressBookRef addressBookInit = ABAddressBookCreate();
CFMutableArrayRef abContacts =
(CFMutableArrayRef)ABAddressBookCopyArrayOfAllPeople(addressBookInit); // get array of all contacts
CFArraySortValues (abContacts, CFRangeMake(0, CFArrayGetCount(abContacts)), (CFComparatorFunction)ABPersonComparePeopleByName, (void *)ABPersonGetSortOrdering());
NSArray *copypeople = (NSArray *) abContacts;
NSMutableArray *tempTheadlist = [[NSMutableArray alloc] init];
for (int i=0; i < copypeople.count; i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ABRecordRef record = [copypeople objectAtIndex:i];
if (blah blah)
[tempThreadList addObject: someObject];
[pool release];
}
// POINT OF CRASH AFTER LOOP ENDS
if (tempTheadlist.count > 0)
[NSThread detachNewThreadSelector: @selector(loading_pictures:) toTarget:self withObject:tempTheadlist];
[tempTheadlist release];
[copypeople release];
CFRelease(addressBookInit);
Any reason why it should crash at any point here?