Debian Codegraph @

src/com/bulenkov/iconloader/util/SoftReference.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2016 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.bulenkov.iconloader.util;
18
19 import org.jetbrains.annotations.Nullable;
20
21 import java.lang.ref.Reference;
22 import java.lang.ref.ReferenceQueue;
23
24 /**
25 * The class is necessary to debug memory allocations via soft references. All IDEA classes should use this SoftReference
26 * instead of original from java.lang.ref. Whenever we suspect soft memory allocation overhead this easily becomes a hard
27 * reference so we can see allocations and memory consumption in memory profiler.
28 *
29 * @author max
30 */
31 @SuppressWarnings("ClassNameSameAsAncestorName")
32 public class SoftReference<T> extends java.lang.ref.SoftReference<T> implements Getter<T> {
33 //private final T myReferent;
34
35 public SoftReference(final T referent) {
36 super(referent);
37 //myReferent = referent;
38 }
39
40 public SoftReference(final T referent, final ReferenceQueue<? super T> q) {
41 super(referent, q);
42 //myReferent = referent;
43 }
44
45 //@Override
46 //public T get() {
47 // return myReferent;
48 //}
49
50 @Nullable
51 public static <T> T dereference(@Nullable Reference<T> ref) {
52 return ref == null ? null : ref.get();
53 }
54 @Nullable
55 public static <T> T deref(@Nullable Getter<T> ref) {
56 return ref == null ? null : ref.get();
57 }
58 }