Here you can find the source of memoryUsedInMB()
public static long memoryUsedInMB()
//package com.java2s; //License from project: Open Source License public class Main { public static final long MEGA = 1048576; /**/*from w w w.ja va2 s . c o m*/ * Returns the amount of memory currently used by the JVM, in megabytes. * @return */ public static long memoryUsedInMB() { return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / MEGA; } }