Here you can find the source of getUsedMemory()
public static String getUsedMemory()
//package com.java2s; //License from project: Open Source License public class Main { public static final long MEGA = 1048576; /**//from ww w. jav a 2 s. c o m * Returns a string which describes the amount of memory currently used by the JVM heap. * @return a string which describes the amount of memory currently used by the JVM heap. */ public static String getUsedMemory() { final Runtime runtime = Runtime.getRuntime(); return "Used memory: " + String.valueOf((runtime.totalMemory() - runtime.freeMemory()) / MEGA) + " MB"; } }