---
title: "PhantomReference"
author: "tmrp"
date: "2010-06-01T13:36:07Z"
tags: []
categories: ["编程语言"]
slug: "phantomreference"
draft: false
lastmod: "2010-06-01T13:37:55Z"
id: 680811
url: "https://tmrp.iteye.com/blog/680811"
---

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