Memory management in objective-c

Posted by prathumca on Stack Overflow See other posts from Stack Overflow or by prathumca
Published on 2010-03-11T09:59:27Z Indexed on 2010/03/12 19:07 UTC
Read the original article Hit count: 548

I have this code in one of my classes:

- (void) processArray
{

   NSMutableArray* array = [self getArray];
   . . .
   [array release];
   array  = nil;
}


- (NSMutableArray*) getArray
{
   //NO 1:
   NSMutableArray* array = [[NSMutableArray alloc]init];

   //NO 2:
   NSMutableArray* array = [NSMutableArray array];
   . . .
   return array;
}

NO 1: I create an array and return it. In the processArray method I release it.

NO 2: I get an array by simply calling array. As I'm not owner of this, I don't need to release it in the processArray method.

Which is the best alternative, NO 1 or NO 2? Or is there a better solution for this?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone-sdk