Why are Phantom References not cleared as they are enqueued?

后端 未结 2 456
无人共我
无人共我 2020-12-15 07:04

We can see that "phantom reachable" is as unreachable as "unreachable": §

An object is phantom reachable if it is neither st

2条回答
  •  一向
    一向 (楼主)
    2020-12-15 07:34

    This was changed in JDK 9. Now phantom references are cleared as soft and weak references do. And the corresponding paragraph was removed from the Javadoc.

    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.

提交回复
热议问题