Here you can find the source of getMemoryUsage()
public static long getMemoryUsage()
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. j a va 2 s .c o m*/ * Gets memory usage, in MB * @return */ public static long getMemoryUsage() { long memory = Runtime.getRuntime().totalMemory(); return Math.round(memory / Math.pow(2, 20)); } }