Here you can find the source of sampleFreeMemory()
public static double sampleFreeMemory()
//package com.java2s; public class Main { static long startMemory; public final static int KILO = 1024; /**/*w w w.j a v a 2 s. c om*/ * Get current free memory<br> * The current memory is saved for Memory usage analysis * @return Free memory in MegaBytes */ public static double sampleFreeMemory() { startMemory = Runtime.getRuntime().freeMemory(); return ConvertByteToMegaByte(startMemory); } public static double ConvertByteToMegaByte(long byteUnits) { return (double) byteUnits / (KILO * KILO); } }