Hi,
I have this array that I created using [[NSMutallableArray alloc] init],
What is the best way to clear and free up memory and when should I do it?
Method 1:
for(int i=0;i<[arrTiles count];i++)
{
[arrTiles removeObjectAtIndex:i];
}
[arrTiles release];
Method 2:
arrTiles = nil;
[arrTiles release];
I'm thinking method 2 would be better b/c I don't have iterate through the entire array. Is setting an array to nil an expensive operation comparing to loop iteration?
Please tell me if there's a better way to release arrays.
Should I release it when I'm done with it in a method then re-allocate it when I need it again? or should I just let it hang around?
Does the rules as when to release depend on whether how the array was declared?
for example, either
[[NSMutableArray alloc] initWithCapacity:10]
or
[[NSMutallableArray alloc] init];
?
Thanks,
-FerrariX