Here you can find the source of getMemoryUsed()
public static int getMemoryUsed()
//package com.java2s; public class Main { public static int getMemoryUsed() { int mb = 1024 * 1024; Runtime runtime = Runtime.getRuntime(); int memoryUsed = (int) ((runtime.totalMemory() - runtime.freeMemory()) / mb); return memoryUsed; }/*from ww w. j a v a2s . c o m*/ }