Re: Are these the same and correct?
Re: Are these the same and correct?
- Subject: Re: Are these the same and correct?
- From: Chris Hanson <email@hidden>
- Date: Mon, 14 Nov 2005 12:10:02 -0800
On Nov 14, 2005, at 11:42 AM, Sherm Pendley wrote:
But, as a matter of internal implementation details, there's no
guarantee that n is autoreleased in the second case, although it
quite often will be.
In the second case, you must always treat the object pointed to by
"n" as autoreleased
No, you treat it as something for which you are not responsible. It
might be autoreleased, it might be a constant, a singleton, or
whatever - that's an implementation detail you don't need to worry
about. The sole guarantee is that you don't have to release it.
"Doesn't have to be released" != "Guaranteed to be autoreleased".
There is more than just the guarantee that the developer doesn't have
to release the object.
There is also the guarantee that the developer cannot rely on the the
object's existence beyond the scope of the autorelease pool in which
it was allocated, unless the developer explicitly retains it.
This is something that trips up people new to Cocoa. Your initial
phrasing could lead people to try to "figure out" whether certain
objects are autoreleased before retaining and releasing them, when in
fact they always need to write their code as if these objects are
autoreleased.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden