> 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.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Mike Schilling - 09 Jan 2006 01:06 GMT
> Garbage collection by reference counting is
> practically never done in modern implementations of Java, or of any
> other garbage collected environment.
There's the Unix file system, of course.
Owen Jacobson - 09 Jan 2006 01:32 GMT
>> Garbage collection by reference counting is
>> practically never done in modern implementations of Java, or of any
>> other garbage collected environment.
>
> There's the Unix file system, of course.
Which is guaranteed to be acyclic (no hardlinks to directories) and thus
doesn't suffer from the cycle problem reference-counted systems can have.
Mike Schilling - 09 Jan 2006 02:57 GMT
>>> Garbage collection by reference counting is
>>> practically never done in modern implementations of Java, or of any
[quoted text clipped - 4 lines]
> Which is guaranteed to be acyclic (no hardlinks to directories) and thus
> doesn't suffer from the cycle problem reference-counted systems can have.
Sure; that's one reason reference-couting is appropriate.
Another place you might see it is in distributed-object systems, where the
reference and object may live on different nodes of a network. Creating
and deleting references is less common (and already expensive), so the
expense of counting is insignificant, and the cost of distributed true GC is
high.
Chris Uppal - 09 Jan 2006 09:46 GMT
> Another place you might see it is in distributed-object systems, where the
> reference and object may live on different nodes of a network.
And, of course, RC is the basis of object lifetime management in COM.
-- chris
Dimitri Maziuk - 10 Jan 2006 00:49 GMT
Chris Smith sez:
>> 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
[quoted text clipped - 5 lines]
> "there is no spoon" tone.) Garbage collection by reference counting is
> practically never done in modern implementations of Java,
There's a rumour that IBM has a reference-counting JVM and they
use it for busy-server type programs ->
>... The ONLY good reasons to use reference
> counting are if you need deterministic object destruction
-> for precisely that reason: non-deterministic GCs are not very
suitable for certain tasks.
Dima

Signature
...the mainstream products of major vendors largely ignore these demonstrated
technologies... [Instead, their customers] are left with several ineffective
solutions collected under marketing titles like "defense in depth".
-- Thirty Years Later: Lessons from the Multics Security Evaluation
Mike Schilling - 10 Jan 2006 04:13 GMT
> Chris Smith sez:
>>> Is there a quick way to set a reference count to zero manually, instead
[quoted text clipped - 12 lines]
> There's a rumour that IBM has a reference-counting JVM and they
> use it for busy-server type programs ->
Programs where it's important to run out of memory?
Chris Uppal - 10 Jan 2006 10:29 GMT
> > There's a rumour that IBM has a reference-counting JVM and they
> > use it for busy-server type programs ->
>
> Programs where it's important to run out of memory?
If such a beast existed (which is possible, at least as a research project),
then it wouldn't use /pure/ reference counting.
-- chris
Dimitri Maziuk - 10 Jan 2006 16:48 GMT
Chris Uppal sez:
>> > There's a rumour that IBM has a reference-counting JVM and they
>> > use it for busy-server type programs ->
>>
>> Programs where it's important to run out of memory?
Programs where it's important to have upper bound on
suckage.
> If such a beast existed (which is possible, at least as a research project),
> then it wouldn't use /pure/ reference counting.
No, apparently there's some cycle-detecting magic in there.
Of course, I saw it on the web somewhere and as we all know
everything one sees on the web is true.
Dima

Signature
The most horrifying thing about Unix is that, no matter how many times you hit
yourself over the head with it, you never quite manage to lose consciousness.
It just goes on and on. -- Patrick Sobalvarro
On Sun, 8 Jan 2006 23:38:08 +0000 (UTC), Peter Jones
<ant_on_line@hotmail.REMOVEHERE.com> wrote, quoted or indirectly
quoted someone who 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.
>Many thanks in advance.
There are no reference counts. See
http://mindprod.com/jgloss/garbagecollection.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.