Peter Jones said:
Is there a quick way to set a reference count to zero manually, instead of
waiting for the GC to do it for you? I know that System.gc() will perform a
quick garbage collection which is great, but i have some objects I would
like to set reference count to zero before this happens to make sure they
go.
There is no reference count. (Imagine that spoken in a Matrix-like
"there is no spoon" tone.) Garbage collection by reference counting is
practically never done in modern implementations of Java, or of any
other garbage collected environment. It's not done because it is slow
and it doesn't work. There are variations that do work; they are not
just slow but unimaginably slow. The ONLY good reasons to use reference
counting are if you need deterministic object destruction (and don't
mind paying for it in correctness, as well as speed), or if you're
trying to explain garbage collection to someone who is unlikely to
understand more realistic algorithms.
What's more often done is copy collection, or more rarely mark-and-
sweep. Neither has a reference count.
Even if reference counting were used, the virtual machine wouldn't let
you set one automatically to zero, because you would be able to
circumvent the platform security model and create errors that lead to
undefined (and potentially non-portable) behavior.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation