Phantom Referenced Objects

前端 未结 6 1545
星月不相逢
星月不相逢 2021-02-15 19:49

Phantom References serve for post-mortem operations. The Java specification states that a phantom referenced object will not be deallocated until the phantom-re

6条回答
  •  既然无缘
    2021-02-15 20:18

    I think the idea is to let other objects do extra cleanup above and beyond what the original object does. For example, if the original object cannot be extended to implement some finalization stuff, you can use phantom references.

    The bigger problem is that the JVM makes no guarantee that an object will ever be finalized, and I assume by extension no guarantee that phantom references get to do their thing post-finalization.

提交回复
热议问题