X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FMemWatch.java;h=aaaed12eb813a828c803cd3d3513d5bed93d7520;hb=785f638bab44e70ec6103c3891daea95bcda9a07;hp=2683e7f46d9b81f28bfbe277e169c9b999833f32;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/MemWatch.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/MemWatch.java index 2683e7f46..aaaed12eb 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/MemWatch.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/MemWatch.java @@ -1,34 +1,34 @@ -package org.simantics.db.impl; - -import java.lang.ref.WeakReference; - -public class MemWatch { - public static boolean isLowOnMemory() { - return isLowOnMemory; - } - private static boolean DBBUG = false; - private static boolean isLowOnMemory = false; - @SuppressWarnings("unused") - private static MemWatch memWatch = new MemWatch(); - private Runtime runtime = Runtime.getRuntime(); - @SuppressWarnings("unused") - private WeakReference ref = new WeakReference(new Watch()); - class Watch { - @Override - protected void finalize() throws Throwable { - long fre = runtime.freeMemory(); - long tot = runtime.totalMemory(); - long max = runtime.maxMemory(); - if (tot < max || fre > max / 20) - isLowOnMemory = false; - else - isLowOnMemory = true; - if (DBBUG) - System.err.println("Garbage was collected using " + Thread.currentThread().getName() - + " fre=" + fre + " tot=" + tot + " max=" + max - + " low=" + isLowOnMemory); - ref = new WeakReference(new Watch()); - super.finalize(); - } - } -} +package org.simantics.db.impl; + +import java.lang.ref.WeakReference; + +public class MemWatch { + public static boolean isLowOnMemory() { + return isLowOnMemory; + } + private static boolean DBBUG = false; + private static boolean isLowOnMemory = false; + @SuppressWarnings("unused") + private static MemWatch memWatch = new MemWatch(); + private Runtime runtime = Runtime.getRuntime(); + @SuppressWarnings("unused") + private WeakReference ref = new WeakReference(new Watch()); + class Watch { + @Override + protected void finalize() throws Throwable { + long fre = runtime.freeMemory(); + long tot = runtime.totalMemory(); + long max = runtime.maxMemory(); + if (tot < max || fre > max / 20) + isLowOnMemory = false; + else + isLowOnMemory = true; + if (DBBUG) + System.err.println("Garbage was collected using " + Thread.currentThread().getName() + + " fre=" + fre + " tot=" + tot + " max=" + max + + " low=" + isLowOnMemory); + ref = new WeakReference(new Watch()); + super.finalize(); + } + } +}