Your main.m file should have the following call:
NSApplicationMain(argc, (const char **)argv);
NSApplicationMain()
is responsible for creating the application, i.e., an instance of NSApplication
, which in turn is responsible for creating autorelease pools:
The NSApplication class sets up autorelease pools (instances of the NSAutoreleasePool class) during initialization and inside the event loop—specifically, within its initialization (or sharedApplication) and run methods.
This means that, in the general case, you shouldn’t have to worry about creating autorelease pools since NSApplication
already does that in both the initialisation and in the event loop. There are situations where creating your own autorelease pools might be necessary/desirable, e.g. a method that has a loop that creates many autoreleased objects. In this case, it’s a good idea to have an autorelease pool for each loop iteration.