Here you can find the source of getMemoryInUse()
public static int getMemoryInUse()
//package com.java2s; public class Main { /**//from w w w . j ava 2 s .c o m * Returns the number of megabytes (MB) of memory in use. */ public static int getMemoryInUse() { Runtime runtime = Runtime.getRuntime(); long mb = 1024 * 1024; long total = runtime.totalMemory(); long free = runtime.freeMemory(); return (int) ((total - free) / mb); } }