So the standard rule is if an object is created with alloc, copy or retained, it needs a subsequent release. Objects created with convenience methods are autoreleased.
But what about temp vars defined with “=” and used in the scope of a method? eg
NSError *error = nil;
NSString *tempString = @"foo";
int number = otherInt * 32;
NSUInteger row = [indexPath row];
NSArray *sameArrayDifferentPointer = otherArray;
or even
NSArray *sameArrayDifferentPointer = (*NSMutableArray) otherMutableArray;
I know the last one is ‘bad’ but compiles fine and doesn’t throw exceptions.
error,numberandrowaren’t objects (or pointers to objects) so they don’t need to be (and indeed can’t be) released. (numberis an int,rowis either an unsigned int or an unsigned long,erroris a pointer to nil.)tempStringwill be autoreleased—the lineis the equivalent of
Writing it the second way makes it clearer what’s going on. Likewise, your arrays are the equivalent of calling
[NSArray arrayWithArray:otherArray].