开发者

Memory leak in NSMutableArray allocation

I am getting memory leak in NSMutableArray allocation.. in

NSMutableArray *contactsArray =[[NSMutableArray alloc] init]; 

CODE:

+(NSMutableArray*)getContacts
{
    addressBook = ABAddressBookCreate();

    NSArray* peopleArray =  (NSArray*) ABAddressBookCopyArrayOfAllPeople(addressBook);

    int noOfPeople = [peopleArray count];

    NSMutableArray *contactsArray =[[NSMutableArray alloc] init]; 

    for ( int i = 0; i < noOfPeople; i++)
    {
        ABRecordRef person =   [peopleArray objectAtIndex:i];
        ABRecordID personId = ABRecordGetRecordID(person);
        NS开发者_StackOverflowString* personIdStr = [NSString stringWithFormat:@"%d", personId];

        ContactDTO* contactDTO = [AddressBookUtil getContactDTOForId:personIdStr];


        [contactsArray addObject:contactDTO];

    }
    [peopleArray release];
    return contactsArray;

}


It is standard procedure that objects returned from methods (in your case, contactsArray) are autoreleased before returning. You could either return [contactsArray autorelease]; or create it already autoreleased with [NSMutableArray arrayWithCapacity:noOfPeople]


You need to release contactsArray manually somewhere, because it does not define autorelease.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜