Howto keep track of GC, without letting the monitored object die?

Clemens Eisserer linuxhippy at gmail.com
Wed Mar 25 08:57:53 PDT 2009


Hello,

First of all sorry for beeing off-topic.
I am developing a distributed object system, where I need to keep
track wether an Object is still referenced, without actually let it
die.
Only if server- and client-side object are no longer referenced, they
both may be freed by the GC.

With finalizers I would be able to do something like this:

class SharedObject {
    private Object gcMonitor = new Object() {
         protected void finalize() {
            RefernceManager.addStrongReference(SharedObject.this);
            Server.objectUnreferenced(SharedObject.this);
        }
    }
}

Once the server knows both parts are unreferenced, it can release all
strong references and the object can be reclaimed by the GC.

However I fear that this would really stress the jvm. Is it possible
to archive the same using References and ReferenceQueues?
Are there patterns which make the knowledge about the object obsolete?

Thanks, Clemens



More information about the hotspot-gc-dev mailing list