My question is regarding the scope of the object created in +planet. I have been told that "autoreleased objects will stay around for the duration of the method/function they were created in" In my example I am assuming that the scope for the planet instance is within main() and not within the method where I do the initial alloc/init?
+(Planet *) planet {
gPlanetCount++;
return [[[self alloc] init] autorelease];
}
int main(int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Planet *outerMost;
outerMost = [Planet planet];
...
... some code
...
[pool drain];
return 0;
}
EDIT_001
int main(int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Planet *outerMost;
outerMost = [[Planet planet] retain]; // Added retain
...
... some code
...
[outerMost release]; // Added release
[pool drain];
return 0;
}
gary