There will be no memory leak in this code, and freeing the array itself will crash when the array is auto-implemented at the end of the run loop.
Most Cocoa classes provide several ways to create a new object and are very consistent with this convention:
[[NSSomeObject alloc] init] : you are responsible for freeing the object (instance method).
[NSSomeObject someObject] : the object will be auto-implemented for you, usually at the end of the execution loop (class method). This is roughly equivalent to [[[NSSomeObject alloc] init] autorelease] .
Proper use of the instance method will be:
a = [[NSMutableArray alloc] init]; // do stuff [a release];
Proper use of the class method will be:
a = [NSMutableArray array]; // do stuff, array is in the autorelease pool
Please note that Apple recommended avoiding convenient methods to improve performance as much as possible. This is controversial advice , cannot save a lot of CPU time and separates alloc-init from release on an object that you might not really care about storage.
source share