There are (I would say) 3 main instances when they are created and released:
1. The beginning and very end of the life cycle of your application, written in main.m
int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; }
2. The beginning and end of each event (done in AppKit)
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)loadView [pool release];
3. When you want (you can create your own pool and free it. [From apple memory management document])
– (id)findMatchingObject:anObject { id match = nil; while (match == nil) { NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init]; match = [self expensiveSearchForObject:anObject]; if (match != nil) { [match retain]; } [subPool release]; } return [match autorelease]; }
source share