Phantom Referenced Objects

前端 未结 6 1025
悲哀的现实
悲哀的现实 2021-02-15 20:04

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:37

    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.

提交回复
热议问题