Autorelease pool questions
Autorelease pool questions
- Subject: Autorelease pool questions
- From: Brian Gilman <email@hidden>
- Date: Sun, 19 Jan 2003 13:01:23 -0500
On 1/19/03 12:24 PM, "j o a r" <email@hidden> wrote:
O.K.
I've read the stepwise docs and the list and now I have some more
questions that I need clarification on:
Step wise uses the example below:
(id) findSomething
{
id theObject = nil;
// Whatever we're looking for
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
// Autoreleased objects are now automatically placed in localPool.
// Loop that creates many temporary objects
while ( theObject == nil )
{
...
if ( [temporaryObject matchesSomeCondition] )
{
theObject = [temporaryObject retain];
// We want this one
}
}
// Get rid of all those temporary objects
[localPool release];
return [theObject autorelease];
}
My question is:
If all objects are getting placed in this autorelease pool, and the pool
get's released before I return my object out of this method, am I not
sending back a reference to a null object?? Or, because I tell the runtime
to retain the temporaryObject, this object's reference count is set to 1 and
not collected on the next clean up cycle?? I may not be using the right
terminology here because I'm new to this stuff so please stick with me on
this.
I'm thinking that an NSAutoReleasePool is something like a parameterized
vector that I temporarily stuff objects into. When I use the statement:
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
I'm hinting to the compiler that the objects that I'm about to use are
temporary. Somehow the obj-c runtime sets up a temp memory area for me and
starts allocation memory out of there. And that if I use a autorelease pool
I can tell the pool to retain some of these objects and clean up others.
Grrr....I think I need to read more.....
Best,
-B
--
Brian Gilman <email@hidden>
Group Leader Medical & Population Genetics Dept.
MIT/Whitehead Inst. Center for Genome Research
One Kendall Square, Bldg. 300 / Cambridge, MA 02139-1561 USA
phone +1 617 252 1069 / fax +1 617 252 1902
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.