Here you can find the source of getUsedMemory()
static public long getUsedMemory()
//package com.java2s; /*/*from w w w.j a va 2 s. c om*/ * Licensed under the Apache License, Version 2.0 (the "License"): http://www.apache.org/licenses/LICENSE-2.0 */ public class Main { static public long getUsedMemory() { Runtime rt = Runtime.getRuntime(); long usedMB = (rt.totalMemory() - rt.freeMemory()) / 1024 / 1024; return usedMB; } }