NSMutableArray memory management

Posted by chicken on Stack Overflow See other posts from Stack Overflow or by chicken
Published on 2009-01-19T00:36:48Z Indexed on 2010/05/20 3:50 UTC
Read the original article Hit count: 231

Filed under:
|
|
|
NSMutableArray *a1 = [[NSMutableArray alloc] init];
NSMutableArray *a2 = [NSMutableArray array];

TempObj *obj = [[TempObj alloc] init]; //assume this line is repeated for each obj
[a1 addObject:obj];
[a1 addObject:obj2];
[a1 addObject:obj3];
[a1 addObject:obj4];

[obj release];
[obj2 release];
[obj3 release];
[obj4 release];

[a1 release];

Ok so a2 is an autorelease obj so i dont have to call release on it? Also how do you know when you get an autorelease object?

And for a1, i dont have to loop through the array and release each object first? What if i called [a1 removeAllObjects]; does that call [[a1 objectAtIndex:#] release];

Am i supposed to release those objects after ive added them to the array?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about osx