setting a reference count to zero

P

Peter Jones

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

Chris Smith

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
 
M

Mike Schilling

Chris Smith said:
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.
 
O

Owen Jacobson

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

Mike Schilling

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

Roedy Green

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
 
C

Chris Uppal

Mike said:
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
 
D

Dimitri Maziuk

Chris Smith sez:
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,

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
 
M

Mike Schilling

Dimitri Maziuk said:
Chris Smith 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?
 
C

Chris Uppal

Mike said:
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
 
D

Dimitri Maziuk

Chris Uppal sez:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top