ITeye博客

PhantomReference

tmrp · 2010-06-01 13:36 · 编程语言 · Markdown

在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已经在内存中删除。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。