在java中,引用的强度有以下四个级别:1.Strong Referece 2. soft reference 3. weak reference 4 PhantomReference
关于PhantomReference有以下几点需要注意:
1 the PhantomReference.get() method always returns null
2 another difference is that the PhantomReference is enqueueed only after the finalize() method has been called.
3 If you want the reference to be added to the reference queue, you have to keep a strong reference to the Phantom reference.(这一点很重要,为了保持phantom reference被回收后,添加到reference queue中,必须有一个strong reference 引用到这些phantom reference)
当phantom reference 被enqueue到队列时,phantom reference引用的referent已经在内存中删除。
关于PhantomReference有以下几点需要注意:
1 the PhantomReference.get() method always returns null
2 another difference is that the PhantomReference is enqueueed only after the finalize() method has been called.
3 If you want the reference to be added to the reference queue, you have to keep a strong reference to the Phantom reference.(这一点很重要,为了保持phantom reference被回收后,添加到reference queue中,必须有一个strong reference 引用到这些phantom reference)
当phantom reference 被enqueue到队列时,phantom reference引用的referent已经在内存中删除。
本文深入探讨了Java中四种引用类型的特性,重点介绍了PhantomReference的特点及其使用方式。文章指出PhantomReference.get()总是返回null,并强调为了使PhantomReference被加入引用队列,必须保留对其的强引用。
215

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



