• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Autorelease pool questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Autorelease pool questions
      • From: j o a r <email@hidden>
    • Re: Autorelease pool questions
      • From: Nicholas Riley <email@hidden>
References: 
 >Re: Memory management questions using UUID example (From: j o a r <email@hidden>)

  • Prev by Date: Re: Memory management questions using UUID example
  • Next by Date: Re: NSOpenGLView with transparent background
  • Previous by thread: Re: Memory management questions using UUID example
  • Next by thread: Re: Autorelease pool questions
  • Index(es):
    • Date
    • Thread