PDA

View Full Version : Embedded Autorelease Pools




Jordan72
Dec 28, 2005, 06:56 PM
Objects are automatically added to the auto release pool that is on the top of the stack, like objects that are returned from NSStrings and NSNumber class methods, -numberWithInt and -stringWithString.

I have a situation where I want some objects that are created in a nested pool to be in added only to the outer pool.

I don't want them added to the inner pool, even though I need to create them within in this pool. How do I create objects, but at the same time add them to a pool that is not currently at the top of the stack?



Jordan72
Dec 29, 2005, 06:20 PM
I found the answer to my question, so I'm posting the answer.

I retain the object, so it will last beyond the scope of the inner pool. And, I send an -addObject: message to the outer pool, where the argument is the object I'm adding to the pool.