Here you can find the source of memoryUsed()
private static long memoryUsed()
//package com.java2s; //License from project: Apache License public class Main { /**/* w w w . j a v a2 s. co m*/ * Returns the amount of memory on the heap that is currently being used by the JVM. * * @return */ private static long memoryUsed() { Runtime rt = Runtime.getRuntime(); return rt.totalMemory() - rt.freeMemory(); } }