Path: blob/master/jcl/src/java.base/share/classes/java/lang/ref/SoftReference.java
12521 views
/*[INCLUDE-IF Sidecar16]*/1package java.lang.ref;23/*******************************************************************************4* Copyright (c) 1998, 2020 IBM Corp. and others5*6* This program and the accompanying materials are made available under7* the terms of the Eclipse Public License 2.0 which accompanies this8* distribution and is available at https://www.eclipse.org/legal/epl-2.0/9* or the Apache License, Version 2.0 which accompanies this distribution and10* is available at https://www.apache.org/licenses/LICENSE-2.0.11*12* This Source Code may also be made available under the following13* Secondary Licenses when the conditions for such availability set14* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU15* General Public License, version 2 with the GNU Classpath16* Exception [1] and GNU General Public License, version 2 with the17* OpenJDK Assembly Exception [2].18*19* [1] https://www.gnu.org/software/classpath/license.html20* [2] http://openjdk.java.net/legal/assembly-exception.html21*22* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception23*******************************************************************************/2425/**26* SoftReference objects are used to detect referents which27* are no longer visible and who's memory is to be reclaimed.28*29* @author OTI30* @version initial31* @since 1.232*/33public class SoftReference<T> extends java.lang.ref.Reference<T> {34/*[PR 124242] SoftReference.get() should reset age */35private volatile int age;3637/**38* Constructs a new instance of this class.39*40* @param r referent to track.41* @param q queue to register to the reference object with.42*/43public SoftReference(T r, ReferenceQueue<? super T> q) {44initReference(r, q);45}4647/**48* Constructs a new instance of this class.49*50* @param r referent to track.51*/52public SoftReference(T r) {53initReference(r);54}5556/**57* Return the referent of the reference object.58*59* @return Referent to which reference refers,60* or null if object has been cleared.61*/62public T get () {63/*[PR 124242] SoftReference.get() should reset age*/64if (age != 0) {65age = 0;66}67return super.get();68}69}707172