Re: retain and autorelease
Re: retain and autorelease
- Subject: Re: retain and autorelease
- From: Wade Tregaskis <email@hidden>
- Date: Sat, 15 Nov 2003 13:20:01 +1100
An unretained object like that is in the autorelease pool of a method
up the call stack, and you can't
(without setjmp/longjmp) get back up there without first passing back
into your method. An object like that is fine.
i see, so an object that's got from a convenience method by your
method and not retained by your method, is absolutely guaranteed to at
least hang round until the end of your method (as in reaching the end
or coming across a return), so long as nothing else effects it
elsewhere somehow.
i had always been wary of not retaining, even for a short period.
Autorelease pools don't magically work in the background - they won't
interrupt your executing code. So if your method is self-contained,
you have absolute security.*
If you start calling other methods, there is a potential danger, but it
is miniscule. If some method ends up getting called that does tricksy
stuff with the current runloop, it could conceivably cause the current
autorelease pool to empty itself. However, in my experience this
doesn't happen - for whatever reason, there is no way to prematurely
empty an autorelease pool; even running the current runloop again seems
to create a new autorelease pool, and somehow keep hold of the old one.
Presumably the autorelease pool is kept in the stack, created by the
relevant NSRunLoop method(s), so no method further down the stack can
touch it (aside from adding objects to it).
So, in summary, there should be no way for an object to be autoreleased
within your method, regardless of what you call in it. Unless of
course someone explicitly releases the autorelease pool. But there's
only two cases I can think of where that would happen - (a) buggy code,
(b) controlling your own autorelease pool(s), in which case you should
be able to manage everything anyway.
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
* = Ignoring any threading issues. Since it's both normal and good
form to not share autorelease pools between threads, this shouldn't be
a problem either.
_______________________________________________
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.