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?