The difference is in exactly when the enqueuing happens.[color=red] WeakReferences are enqueued as soon as the object to which they point becomes weakly reachable. This is before finalization or garbage collection has actually happened;[/color] in theory the object could even be "resurrected" by an unorthodox finalize() method, but the WeakReference would remain dead.[color=red] PhantomReferences are enqueued only when the object is physically removed from memory[/color], and the get() method always returns null specifically to prevent you from being able to "resurrect" an almost-dead object.
Difference between WeakReference and PhantomReference
最新推荐文章于 2022-08-24 15:28:54 发布
本文详细解释了弱引用和幽灵引用的概念,重点在于它们何时被排队以及如何影响对象的生命周期。
945

被折叠的 条评论
为什么被折叠?



