Here you can find the source of getUsedMemory()
public static long getUsedMemory()
//package com.java2s; // Refer to LICENSE for terms and conditions of use. public class Main { /**//from w w w.java2 s . c om * Return the number of memory bytes used, which is computed by subtracting * the 'free' memory from 'total' memory. * * @return number of bytes of memory used */ public static long getUsedMemory() { long total = Runtime.getRuntime().totalMemory(); long free = Runtime.getRuntime().freeMemory(); return total - free; } }