Here you can find the source of getUsedMemory()
public static int getUsedMemory()
//package com.java2s; //License from project: Open Source License public class Main { /**/* ww w . j a v a 2s. c o m*/ * Returns the current amount of memory (in MB) this JVM is using. * * @return used memory */ public static int getUsedMemory() { return getAllocatedMemory() - getFreeMemory(); } /** * Returns the allocated amount of memory (in MB) this JVM is using. * * @return allocated memory */ public static int getAllocatedMemory() { return Math.round((float) (Runtime.getRuntime().totalMemory() / 1048576L)); } /** * Returns the free amount of memory (in MB) belonging to JVM. * * @return free memory */ public static int getFreeMemory() { return Math.round((float) (Runtime.getRuntime().freeMemory() / 1048576L)); } }