• 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
create an autorelease pool in the init-method and release it in the dealloc-method ..?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

create an autorelease pool in the init-method and release it in the dealloc-method ..?


  • Subject: create an autorelease pool in the init-method and release it in the dealloc-method ..?
  • From: Martin Batholdy <email@hidden>
  • Date: Sun, 15 May 2011 01:43:33 +0200

Hi,


I still have trouble understanding the autorelease pool.

Lets assume an object Z has a method where it gets a string y and returns another string x.

Now when an instance of this object is created and the method is invoked,
 x is returned and is used somewhere else.

Now this method of object Z should not be the owner of x right?
Because x is used elsewhere.


So I add x to the autorelease-pool to declare that I am not the owner (and won't send it a release message);

x = [[[NSString alloc] init] autorelease];


but where do I release the pool?
And to which pool is it added?


I thought I would create my own pool in the init-method of Z and send it a [pool release] message in the alloc-method.

But I haven't seen that so far in sample code ...



can someone explain me what happens when I add x to the autorelease pool?
And where does it get released when I don't send a release command to the pool?

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: create an autorelease pool in the init-method and release it in the dealloc-method ..?
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: Can't create temporary file
  • Next by Date: Re: create an autorelease pool in the init-method and release it in the dealloc-method ..?
  • Previous by thread: Re: NSPostWhenIdle not doing its job?
  • Next by thread: Re: create an autorelease pool in the init-method and release it in the dealloc-method ..?
  • Index(es):
    • Date
    • Thread