Hi, I was reading the Memory Management Guide for IPhone OS and I didn' t understand a point in the Autorelease Pools section Listing - 1 code example :
void main()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *args = [[NSProcessInfo processInfo] arguments];
for (NSString *fileName in args) {
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
NSError *error = nil;
NSString *fileContents = [NSString stringWithContentsOfFile:fileName
encoding:NSUTF8StringEncoding error:&error];
/* Process the string, creating and autoreleasing more objects. */
[loopPool release];
}
/* Do whatever cleanup is needed. */
[pool drain];
exit (EXIT_SUCCESS);
}
It says that :
".......Additionally, any autoreleased objects created in the context of the for loop (such as fileName) are released when loopPool is released even if they’re not explicitly sent an autorelease message."
The point that I didn't understand is how the fileName variable is included in the second pool(loopPool) but not the first one(pool). Isn't the fileName created when the first pool is the top most pool in the pool stack ?