开发者

How Phantom reference works?

开发者 https://www.devze.com 2022-12-20 04:49 出处:网络
The API doc says This reference type differs from the others in that it isn\'t meant to be used to access the object, but as a signal that the object has already been finalized, and the garbage coll

The API doc says

This reference type differs from the others in that it isn't meant to be used to access the object, but as a signal that the object has already been finalized, and the garbage collector 开发者_如何学运维is ready to reclaim its memory.

If Phantom reference cannot be used to access the object, how does the garbage collector reclaims the memory used by this object ?


You might find this presentation from Bob Lee to be useful in demystifying the various reference types (slides).


A phantom reference lets you do final touch up closing on an object, even after it has been declared dead — no longer referenced by any live object.
http://mindprod.com/jgloss/phantom.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号