tags:

views:

85

answers:

2

Just curious does NSAutoreleasePool need to be right at the top of main, or can you declare variables before it?

int main (int argc, const char * argv[]) {

    int myNumber;
    int myOtherNumber;

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    [pool drain];
    return 0;
}

cheers -gary-

+2  A: 

You can create the pool at anytime, you just don't want to declare Autorelease variables before you declare the pool.

jeffamaphone
That should be "you don't want to autorelease objects" — there's no such thing as an autorelease variable and obviously no way of creating one.
Chuck
Yeah, you're right. Don't do the autoreleasy thing with no pool.
jeffamaphone
@jeff +1 for legitimate use of "autoreleasy" =D
Dave DeLong
+2  A: 

Unless you are not allocating any Objective-C objects (and autoreleasing them) you should be fine. I don't know why you want to do this?

Diederik Hoogenboom
I was just curious, I will declare things underneath, seems better practice ... thank you
fuzzygoat