views:

62

answers:

1

Hi,

If I'm correct then the releasing of the pool of autoreleased objects has something to do with the run loop.. I barely have an idea of what that 'run loop' is but my question is, is it possible that the object gets released before the end of the method is reached?

+2  A: 

Like in most frameworks, Cocoa has a loop which runs continuously and dispatches events in response to user input, system events, etc. Most of your code executes inside this loop to handle events. This loop is the run loop.

The run loop drains the outermost autorelease pool at the end of reach loop. Thus your autoreleased objects are guaranteed to stay alive for the duration of the method, since the run loop isn't over until the method (and others) have finished.

If you want autoreleased objects to be claimed faster, e.g. you have a tight inner loop which is creating lots of autoreleased objects, you may setup your own autorelease pools and drain them at the end of each inner loop.

freespace
Short answer: "your autoreleased objects are guaranteed to stay alive for the duration of the method"
Paul Lynch
@Paul Lynch: unless there is a [pool release] or [pool drain] before the end of the method.
JeremyP