Here you can find the source of memoryInfo()
public static String memoryInfo()
//package com.java2s; //License from project: Apache License public class Main { public static String memoryInfo() { Runtime runtime = Runtime.getRuntime(); StringBuilder sb = new StringBuilder(); long maxMemory = runtime.maxMemory(); long allocatedMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); sb.append("heap: ").append(format(allocatedMemory - freeMemory)); sb.append(", allocated: ").append(format(allocatedMemory)); sb.append(", free: ").append(format(freeMemory)); sb.append(", total free: ").append(format(freeMemory + maxMemory - allocatedMemory)); sb.append(", max: ").append(format(maxMemory)); return sb.toString(); }//from w w w .jav a 2s . c om private static String format(long mem) { return Long.toString((long) (mem / 1024. / 1024.)) + "MB"; } }