Here you can find the source of memoryUsage()
public static String memoryUsage()
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . ja v a2s .co m * Calculates the memory usage according to Runtime. * * @return max, total, free and used memory (in bytes) */ public static String memoryUsage() { final Runtime runtime = Runtime.getRuntime(); runtime.gc(); final long max = runtime.maxMemory(); final long total = runtime.totalMemory(); final long free = runtime.freeMemory(); final long used = total - free; return String.format("%d\t%d\t%d\t%d", max, total, free, used); } }