PhantomReference: why not cleared by GC when enqueued?
kirk at kodewerk.com
Thu May 30 13:21:47 UTC 2013
The only useful use case that I've come up with for PhantomReference is to subclass it. In one case it was used as a wrapper so that we'd know when an object was being collected so that we could reap life-cycle information from it. The behaviour was triggered by an JMX control. I suppose there were other ways to do this but given I only wanted to collect when the object was about to be GC'ed.....
On 2013-05-30, at 1:32 PM, Dmytro Sheyko <dmytro_sheyko at hotmail.com> wrote:
> You are listed as an author of java.lang.ref classes. So you must know more than others. Could you shed light on this?
> Thank you,
> From: dmytro_sheyko at hotmail.com
> To: hotspot-gc-dev at openjdk.java.net; core-libs-dev at openjdk.java.net
> Subject: PhantomReference: why not cleared by GC when enqueued?
> Date: Wed, 29 May 2013 14:45:54 +0300
> Why phantom references are not automatically cleared by the garbage collector as they are enqueued?
> Keeping phantom reachable objects in heap has some drawbacks:
> 1. At least 2 GC are required in order to reclaim them, even in case when application code pulls references from reference queue and clears them promptly.
> 2. GC pauses are increased since phantom reachable objects are still to be marked.
> On the other hand, benefits are not obvious. How we can use referent if it's not accessible?
More information about the core-libs-dev