1 package org.simantics.db.impl;
3 import java.lang.ref.WeakReference;
5 public class MemWatch {
6 public static boolean isLowOnMemory() {
9 private static boolean DBBUG = false;
10 private static boolean isLowOnMemory = false;
11 @SuppressWarnings("unused")
12 private static MemWatch memWatch = new MemWatch();
13 private Runtime runtime = Runtime.getRuntime();
14 @SuppressWarnings("unused")
15 private WeakReference<Watch> ref = new WeakReference<Watch>(new Watch());
18 protected void finalize() throws Throwable {
19 long fre = runtime.freeMemory();
20 long tot = runtime.totalMemory();
21 long max = runtime.maxMemory();
22 if (tot < max || fre > max / 20)
23 isLowOnMemory = false;
27 System.err.println("Garbage was collected using " + Thread.currentThread().getName()
28 + " fre=" + fre + " tot=" + tot + " max=" + max
29 + " low=" + isLowOnMemory);
30 ref = new WeakReference<Watch>(new Watch());