• 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
Re: Autopool question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autopool question


  • Subject: Re: Autopool question
  • From: "Dennis C. De Mars" <email@hidden>
  • Date: Tue, 07 Aug 2001 07:59:04 -0700

on 8/7/01 7:26 AM, Lars Hoss at email@hidden wrote:

> Hi!
>
> I have a little question about autorelease pools and how they
> free objects.
> Let's assume I have the following method in the class Foo:
>
> -(MyObject *)object
> {
> // create a MyObject instance somehow ...
> // ref counter on myObject is now 1
> MyObject *myObject = ...
> [myObject autorelease];
> return myObject;
> }
>
> Then I have a method in the class Foe:
>
> -(void)doSomethingWithObject
> {
> Foo *fooInstance = [[Foo alloc] init];
> myObject = [fooInstance object]; // myObject is a class variable
> [myObject retain]; // ref counter now is 2
> [fooInstance release];
> }
>
> The class Foe needs the instance foo for a longer time.
> Since I put myObject into the autorelease pool wouldn't
> it be freed after two event cycles?

No. At the end of the event cycle the autorelease pool is freed and all of
the objects in the pool are released. Your object's retain count is
decreased by one, but since you retained it, it sticks around.

After the pool is released, a fresh pool is created for the next event
cycle. Your object does not remain in the pool for more than one cycle.

- Dennis D.


References: 
 >Autopool question (From: Lars Hoss <email@hidden>)

  • Prev by Date: Re: NSNotification vs message callback?
  • Next by Date: Re: Admin programs and password
  • Previous by thread: Autopool question
  • Next by thread: Inspector Panel
  • Index(es):
    • Date
    • Thread