Manish Pandit ha scritto:
> Hi,
>
> What you get is a copy of a.
that it is a reference that point to that matrix values ...
>The method has 'a' declared as a local
> variable, and it is method-scoped.
so when it returns a is garbaged ...
> Variable z[][] will be {{1,2},{3.4}}
> till you explicitly change it.
because it now point to the reference copy pointed by 'a' ...
Correct interpretation?
Matt Humphrey - 03 Oct 2006 13:04 GMT
> Manish Pandit ha scritto:
>
[quoted text clipped - 3 lines]
>
> that it is a reference that point to that matrix values ...
Yes, you get a copy of the reference to object. There is still only one
object.
>>The method has 'a' declared as a local
>> variable, and it is method-scoped.
>
> so when it returns a is garbaged ...
"a" is not garbage collected. It is a variable (a name) and it goes out of
scope at the end of the method. This gives rise to the possibility that
whatever it was pointing to may become inaccessible (and hence eligible for
garbage collection), but the matrix will not be eligible for collection
because there is still a live reference to it. The garbage collector will
reclaim eligible objects at its discretion later.
>> Variable z[][] will be {{1,2},{3.4}}
>> till you explicitly change it.
>
> because it now point to the reference copy pointed by 'a' ...
z points to the same (identity) object that a pointed to.
> Correct interpretation?
Better.
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
josh - 03 Oct 2006 14:02 GMT
Matt Humphrey ha scritto:
> "a" is not garbage collected. It is a variable (a name) and it goes out of
> scope at the end of the method. This gives rise to the possibility that
> whatever it was pointing to may become inaccessible (and hence eligible for
> garbage collection), but the matrix will not be eligible for collection
> because there is still a live reference to it. The garbage collector will
> reclaim eligible objects at its discretion later.
so only objects when have not more reference to them will be garbaged
and not the variables in which there are their references.
Matt Humphrey - 03 Oct 2006 15:59 GMT
> Matt Humphrey ha scritto:
>
[quoted text clipped - 10 lines]
> so only objects when have not more reference to them will be garbaged
> and not the variables in which there are their references.
I think you've got it--it's a matter of distinguishing between the variable,
the reference and the object. Variables hold references to objects and as
long as the variable is in scope, the object can be reached. When the
variable goes out of scope the reference it was holding disappears but the
object still stays. The object will only be eligible for garbage collection
when it can no longer be reached from any point in the program.
I find pictures helpful for this-- http://www.iviz.com/memory%20pointer.gif
A variable going out of scope is the same as having its box (on the diagram)
disappear. It doesn't change the objects at all, but if there are no longer
any arrows to objects, that object is eligible for garbage collection.
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
josh - 04 Oct 2006 08:16 GMT
Matt Humphrey ha scritto:
> I think you've got it--it's a matter of distinguishing between the variable,
> the reference and the object. Variables hold references to objects and as
> long as the variable is in scope, the object can be reached. When the
> variable goes out of scope the reference it was holding disappears but the
> object still stays. The object will only be eligible for garbage collection
> when it can no longer be reached from any point in the program.
Thanks the answer has been very clear