Yes, you are right, autorelease pools are not recommended for iPhone development when they are not absolutely necessary. They are discouraged because it allows objects to remain in memory longer than necessary; this is a problem when developing applications for the iPhone, where there is not enough memory. Authorized objects are not deallocated until they return to the main auto-resource pool created in main.c, and this can take a long time. (If you have not created your own auto resource pool, I will be the last to talk about it.)
The case when an auto-implemented object is not needed:
NSString *string = [NSString stringWithString:@"hello world"];
In the first case, it’s more convenient , since I don’t have to worry about releasing string later, but it could be easily replaced:
NSString *string = [[NSString alloc] initWithString:@"hello world"];
For these cases, it is recommended that you avoid the auto-implemented object.
When you return objects using autorelease is inevitable .
You should use:
-(NSArray *)findThings { NSArray* things = [[[NSArray alloc] init] autorelease];
Since the object is invalid as soon as you call release .
-(NSArray *)findThings { NSArray* things = [[NSArray alloc] init];
In cases where you use a large amount of autorealized memory, you must create and merge your own autoresist pool so that the autodetection memory does not remain longer than necessary.
-(void)useLotsOfAutoReleasedObjects { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[pool pool] also releases a pool, see NSAutoreleasePool Reference for more information.