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 发布