harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deven You <devyo...@gmail.com>
Subject Re: [drlvm] Should the referent of a PhantomReference be cleared before it is enqueued?
Date Sat, 14 Aug 2010 10:39:49 GMT
I agree with you.
>From my point, the spec means phantom references only be cleared by Java
code, GC won't clear them automatically.  And GC only adds them into the
corresponding reference queue so that Java program can know the change and
 decides whether or not clear these phantom references to make their
referents can be garbage collected.

2010/8/12 Oliver Deakin <oliver.deakin@googlemail.com>

>  I have discovered that DRLVM appears to clear the referent field of a
> PhantomReference before calling its enqueue() method (this can be shown
> quite easily by printing the referent field in Reference.enqueue()). This
> behaviour appears to differ from the RI, on which a non-null referent can be
> got hold of via reflection [1]. The spec for PhantomReference says:
>
> "Unlike soft and weak references, phantom references are not automatically
> cleared by the garbage collector as they are enqueued. An object that is
> reachable via phantom references will remain so until all such references
> are cleared or themselves become unreachable."
>
> This reads to me that soft and weak references clear their referent field
> before being enqueued, but phantom references should only make the referent
> eligible for gc once the referent is no longer phantomly reachable (or
> reachable at all). If this is the case, it would seem that DRLVM's current
> behaviour does not match the spec.
>
> Any comments/thoughts?
>
> Regards,
> Oliver
>
> [1] An example of this kind of use/abuse of PhantomReference can be found
> at:
> http://www.roseindia.net/javatutorials/references.shtml
>
> --
> Oliver Deakin
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message