Why since java 9 PhantomReference java doc states that it is dedicated to the POST-mortem cleanup actions although it was PRE-mortem before

前端 未结 1 739
深忆病人
深忆病人 2021-01-03 12:33

PhantomReference java doc for java 8 and less looks like this:

Phantom reference objects, which are enqueued after the collector determ

相关标签:
1条回答
  • 2021-01-03 13:03

    Since Java 9, PhantomReference (PR) are automatically cleared. What you see is the Javadoc change that comes as the result of that change.

    Before Java 9, the object referenced by PR was kept alive, even though its get() would return null. Therefore, until PR itself is dead, the referent would be technically alive, although you could not acquire the reference to it. The benefits of this behavior are not very clear. Anyhow, PR handling would be the "pre-mortem cleanup".

    After Java 9, PR is cleared right before enqueueing (just like other types of weak/soft refs), the referent itself becomes fully dead before PR is processed by application code, which would be the "post-mortem cleanup".

    0 讨论(0)
提交回复
热议问题