Posted by linuxhippy
on May 6, 2007 at 12:56 PM PDT
I am currently developing some kind of remote-invokation-proxy where objects on the client should be "freed" when they are garbage collected on the server.
I don't know wether I should use Phantom or WeakRefernces in conjunction with a ReferenceQueue. The only thing I need to know is wether an Object was GCed, for now I do this like:
class PhantomIDReference extends PhantomReference<br />
int componentID = 0;<br />
So as soon as one Refernce becomes enqueued I know its componentID and send a call to the client to free that Object.
As I understand both Weak- and PhantomReferences are suited for this task, so where is the benefit from using Phantom- or WeakReferences for this task? Which Referencetype has higher overhead?
Is there a large GC-penality when using Weak/Phantom-References in general?
Any whats the idea behind PhantomReference's specified behaviour to prevent an object from beeing freed if a PhantomReference refers to it, although it can't be reached anyway. Isn't this just unescessary overhead?
Thank you in advance, lg Clemens