autorelease pools are streaming local stacks - you click and pop up. a delayed release message will be sent to the object when the pool is destroyed.
consider this:
NSAutoreleasePool * pool = [NSAutoreleasePool new]; NSNumber * n = [NSNumber numberWithDouble:1.0/17.0]; << n is autoreleased [n self]; << OK! [pool release]; << n is messaged release [n self]; << BAM!
So, when โreallyโ depends on how autocomplete pools are created, but you can always ensure that your objects survive the local pool, so this is never a limitation:
NSAutoreleasePool * pool = [NSAutoreleasePool new]; NSNumber * n = [NSNumber numberWithDouble:1.0/17.0]; << n is autoreleased [n self]; << OK! [n retain]; [pool release]; << n is messaged release [n self]; << OK! [n release]; [n self]; << BAM!
The above is what you must rely on. In some real cases, the object may still be alive where you expect โBAM!โ, But you should never rely on โwell, it should have been destroyed, but everything seems to be in order.โ
source share