views:

89

answers:

2

So I am creating my first opengl es application on the iphone. I want to autorelease an object and that was around the time I noticed that I can't seem to find the location of the autorelease pool.

1) Is the autorelease pool already created for me in an iphone opengl es application? 2) If it is already created for me how often is the pool being drained?

A: 

Under the folder Other Sources I found a file called main.m

it has the autorelease pool. it seems to only drain at the end of the application

Mel
No, it gets drained everytime you go through the runloop. For example, if you are handling a -drawRect, when you return from that -drawRect, you should assume that the pool is being drained - and it probably is.
mahboudz
Also, keep in mind that UIApplication main doesn't actually ever return. So anything that comes after it is not executed. Apps quit via an exit() call.
mahboudz
+1  A: 

Do you have a main.m? If you are using the standard GL ES app template, you should see:

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

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

If so, then you do have an autorelease pool and it gets drained everytime you go through the runloop.

mahboudz
Thanks this is the information I needed. I don't fully understand how it gets drained everytime in the runloop, but I will assume that this code is hidden somewhere in a superclass that I cannot see.
Mel
It is a bit confusing. Here're some links:http://stackoverflow.com/questions/798950
mahboudz
http://stackoverflow.com/questions/581828/autorelease-scope/583292#583292 Note the part: The run loop creates a new autorelease pool before it dispatches an event (such as applicationDidFinishLaunching:) and destroys that pool when the event finishes
mahboudz
By the way, just to make sure you know, you can create your own pool and drain it. You'll have to read up on when it makes sense to do so.
mahboudz