• 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: Stack-based C++ class to wrap NSAutoreleasePool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stack-based C++ class to wrap NSAutoreleasePool


  • Subject: Re: Stack-based C++ class to wrap NSAutoreleasePool
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 16 Nov 2009 17:11:27 -0600

On Nov 16, 2009, at 1:50 PM, Clark Cox wrote:

> Though, if you're planning on returning an
> autoreleased object, you're already assuming that there is an
> autorelease pool in place, in which case, there is no need to wrap the
> local function in your own pool.

> You wouldn't want to wrap such a
> method in an autorelease pool at all; whether or not that pool is tied
> to the method scope is largely irrelevant at that point.

There are reasons to have a local autorelease pool even if you know there is already an autorelease pool in an outer scope.

If you need to return an object from your inner pool to a caller, you retain it, release/drain your inner pool, and then re-autorelease the object before returning it.

With the C++ RAII approach, you'd have to put the StackAutoreleasePool() macro inside a block and put your return outside of it.

Regards,
Ken

_______________________________________________

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

References: 
 >Stack-based C++ class to wrap NSAutoreleasePool (From: Dan Korn <email@hidden>)
 >Re: Stack-based C++ class to wrap NSAutoreleasePool (From: Clark Cox <email@hidden>)
 >Re: Stack-based C++ class to wrap NSAutoreleasePool (From: Kyle Sluder <email@hidden>)
 >Re: Stack-based C++ class to wrap NSAutoreleasePool (From: Clark Cox <email@hidden>)
 >Re: Stack-based C++ class to wrap NSAutoreleasePool (From: BJ Homer <email@hidden>)
 >Re: Stack-based C++ class to wrap NSAutoreleasePool (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: Accessing FilesOwner fm controller
  • Next by Date: Re: NSPopUpButton submenu's
  • Previous by thread: Re: Stack-based C++ class to wrap NSAutoreleasePool
  • Next by thread: Re: Stack-based C++ class to wrap NSAutoreleasePool
  • Index(es):
    • Date
    • Thread