Here you can find the source of getAvailableMemory()
public static long getAvailableMemory()
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j av a2 s. c o m * TODO TEST!! This has changed * * @return total available memory, in bytes. Does not run GC, so this is a fast * call. * @see Runtime#freeMemory() -- which ignores the heap's capacity to grow, so is less * useful! Runtime#freeMemory() can be thought of as "fast memory". */ public static long getAvailableMemory() { Runtime rt = Runtime.getRuntime(); long maxMem = rt.maxMemory(); long freeMem = rt.freeMemory(); long totalMem = rt.totalMemory(); long used = totalMem - freeMem; long available = maxMem - used; return available; } }