Re: Newbie: Object life within a method scope
Re: Newbie: Object life within a method scope
- Subject: Re: Newbie: Object life within a method scope
- From: Justin Spahr-Summers <email@hidden>
- Date: Tue, 22 Feb 2005 16:44:49 -0600
With the same exceptions Apple mentioned (multithreaded, DO), yes, it
is unnecessary to retain an object passed to a method. I don't know if
passing an object to a method increments its retain count at all, but
if it does, it will surely decrement it after the method.
On Tue, 22 Feb 2005 16:59:58 -0500, Joseph Feld <email@hidden> wrote:
> Hi all,
>
> Trying to get a handle on the whole retain and release system (my day job is
> in the Java world and the GC has definitely spoiled me) and I'm curious
> about the life of an object within a method scope. I found the Memory
> Management: Object Ownership and Disposal document on the Apple Dev site and
> it states: "A received object is normally guaranteed to remain valid within
> the method it was received in (exceptions include multithreaded applications
> and some Distributed Objects situations). That method may also safely return
> the object to its invoker," which would seem to answer my question.
> However, two bullet points later it warns: "Use retain and autorelease when
> needed to prevent an object from being invalidated as a normal side-effect
> of a message," which has me a bit confused about what normal side-effects of
> a message might cause me to lose my object.
>
> So I guess my question is, if I'm not interested in an object beyond the
> scope of the method receiving it is it still prudent to retain it to ensure
> it survives the scope, or is that unnecessary?
>
> Thanks,
> Joe
>
_______________________________________________
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