• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.base;
16 
17 import com.google.common.annotations.GwtIncompatible;
18 import java.lang.ref.PhantomReference;
19 import java.lang.ref.ReferenceQueue;
20 
21 /**
22  * Phantom reference with a {@code finalizeReferent()} method which a background thread invokes
23  * after the garbage collector reclaims the referent. This is a simpler alternative to using a
24  * {@link ReferenceQueue}.
25  *
26  * <p>Unlike a normal phantom reference, this reference will be cleared automatically.
27  *
28  * @author Bob Lee
29  * @since 2.0
30  */
31 @GwtIncompatible
32 public abstract class FinalizablePhantomReference<T> extends PhantomReference<T>
33     implements FinalizableReference {
34   /**
35    * Constructs a new finalizable phantom reference.
36    *
37    * @param referent to phantom reference
38    * @param queue that should finalize the referent
39    */
FinalizablePhantomReference(T referent, FinalizableReferenceQueue queue)40   protected FinalizablePhantomReference(T referent, FinalizableReferenceQueue queue) {
41     super(referent, queue.queue);
42     queue.cleanUp();
43   }
44 }
45