Re: Autorelease Question
Re: Autorelease Question
- Subject: Re: Autorelease Question
- From: "Kyle Sluder" <email@hidden>
- Date: Wed, 19 Nov 2008 18:37:39 -0500
On Wed, Nov 19, 2008 at 6:32 PM, Carmen Cerino Jr. <email@hidden> wrote:
> I guess I should also have included what spawned this question in the
> first place. I have read in a handful of places that you can
> guarantee, in the example case, that blah will exist until the end of
> function, and that sometime after the end of the scope of the function
> blah will be released. So if you don't know when it will be released,
> is there a possibility of it being released before control gets back
> to the caller so it can retain it?
The documentation used to be ambiguous on this point, but with the
addition of garbage collection has been rewritten to be more explicit:
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_5.html
"...the Application Kit automatically sets up an autorelease pool
scoped to the application's event cycle."
So when your app finishes processing a message from the WindowServer,
it flushes the autorelease pool. When this happens is sort of
indeterminate, but can't happen in between the return statement and
the next evaluation in the caller, because there's no opportunity for
other code to execute that will run the runloop (which is where the
event cycle lives).
This is all operating under a single-threaded assumption. If you
start multi-threading your app, YMMV.
--Kyle Sluder
_______________________________________________
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