This explanation is correct. If you were to set obj = null then the
object would become eligible for garbage collection. It would not
necessarily get immediately destroyed; in fact it might never get
destroyed if the garbage collector didn't need to make more memory
available.
 
- Gordon

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Erik Price
Sent: Thursday, June 07, 2007 7:20 AM
To: [email protected]
Subject: Re: [flexcoders] Parameter passing !! I am shocked



On 6/7/07, Guido <[EMAIL PROTECTED] <mailto:ptevan%40gmail.com> > wrote:
> I'm not really familiar with technical specifications on how AS
manages argument references. However, I believe this has more to do with
OO Paradigm than with AS.

This is unrelated to the issue at hand.

> On 6/7/07, Jeffry Houser <[EMAIL PROTECTED]
<mailto:jeff%40farcryfly.com> > wrote:
> >
> > I think you missed his point.
> >
> > He sent in obj as a parameter to a function. So objParam should be a
> > reference to obj; and nulling one should definitely null the other.

Not really true.

I think it is more helpful to think of it this way (most popular
languages use this exact same design):

1. When a parameter is passed to a function or method call, it is
ALWAYS pass-by-value (i.e., makes a copy of it local to the function).
But the thing being passed/copied is not the actual object itself,
but rather, a pointer or reference to an object.

2. Therefore, if you pass a reference to an object to a function or
method as a parameter, you have a COPY of the reference, but both your
in-function copy AND your out-of-function original both point to the
same object out there on the heap.

3. Therefore, if you set your parameter reference to null, you're
nulling out your local copy of the reference. But the reference from
outside of the function still exists, and is not set to null (because
only the COPY was set to null). Therefore, the object will not
magically disappear.

To summarize, you can't "set an object to null" in the first place.
You can only set references to objects to null. Therefore, if you
have a reference to object A outside of your function, and a reference
to object A inside of your function, setting one to null does not mean
the other is set to null.

It's all pass by value, just keep in mind it's the REFERENCES that are
getting passed by value (i.e., copied), not the objects themselves.

e


 

Reply via email to