diff --git a/app/src/main/java/io/xpipe/app/util/BindingsHelper.java b/app/src/main/java/io/xpipe/app/util/BindingsHelper.java index 5b8d782d8..7f0aa7183 100644 --- a/app/src/main/java/io/xpipe/app/util/BindingsHelper.java +++ b/app/src/main/java/io/xpipe/app/util/BindingsHelper.java @@ -9,31 +9,17 @@ import lombok.Value; import java.lang.ref.WeakReference; import java.util.HashSet; import java.util.Set; +import java.util.WeakHashMap; import java.util.function.Function; @SuppressWarnings("InfiniteLoopStatement") public class BindingsHelper { - private static final Set REFERENCES = new HashSet<>(); - - static { - ThreadHelper.createPlatformThread("referenceGC", true, () -> { - while (true) { - synchronized (REFERENCES) { - REFERENCES.removeIf(ReferenceEntry::canGc); - } - ThreadHelper.sleep(1000); - - // Use for testing - // System.gc(); - } - }) - .start(); - } + private static final WeakHashMap REFERENCES = new WeakHashMap<>(); public static void preserve(Object source, Object target) { synchronized (REFERENCES) { - REFERENCES.add(new ReferenceEntry(new WeakReference<>(source), target)); + REFERENCES.put(source, target); } }