weak vs phantom references

Mandy Chung mandy.chung at oracle.com
Mon Nov 5 01:54:52 UTC 2018

On 11/3/18 11:13 AM, Per Liden wrote:
> On 2018-11-03 09:58, Michał Zegan wrote:
>> I am asking only for educational purposes.
>> Yes, i sort of remember that PhantomReferences were not cleared when
>> enqueued contrary to all other ones before, but now they are.
>> So if, as said, finalization didn't exist, then for me enqueuing a weak
>> reference seems the same as enqueuing a phantom one, because in both
>> cases they are cleared, and in both cases you cannot access their
>> referents. And such an object would probably also be eligible for
>> collection.
> Yes, if the concept of finalization didn't exist, then weakly 
> reachable and phantom reachable would be the same thing, and there 
> would be no need to separate the two.

Yup.  I realize a typo in my statement:
>>> do think if there were no finalizer at all, it would need two separate
>>> reachability states.

s/need/ not need/


More information about the jdk-dev mailing list