Jon
Mon Feb 23 08:46:17 CST 2004
<<.>> wrote:
> > Where exactly would it set it to null? Would you want it to walk
> > through the entire managed heap (and stack) to find all references to
> > the object? If there are references to the object, why has it been
> > finalized in the first place? Presumably either because the objects
> > referring to it are eligible for garbage collection too, or because it
> > doesn't know the type of the data, in which case it wouldn't know to
> > set that to null anyway.
>
> If it doesnt know where to set it to null, then how does it know what and
> where the object reference is in the first palce.
Usually it does - but you may have some opaque data which the GC
doesn't know about. Don't forget that the GC won't have necessarily
walked all paths where there might be a reference - only paths where
there might be a reference which would keep the object alive.
> Ofcourse it can set the reference to null, its knows where it is, what it is
> and its been destructed, simple matter of setting that reference to null.
But if there are non-null references, why is the object being destroyed
in the first place? It has to be due to all the other references being
within objects which are about to be destroyed anyway - so why do you
care? (Note that the object itself won't be destroyed until everything
that has a reference to it is about to be destroyed - if there's a
finalizer which can access the object, the object can itself be
finalized but not destroyed.)
> > Note that there's no such thing as "setting an object to null" -
> > there's only setting the value of a reference-type variable to null.
>
> Thats what I mean.
Personally I'm happier with it not having to look all over the heap for
things to do when there's no need to.
Why do you think you need it to do this? What's your use case?
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too