Here you can find the source of printMemory()
public static String printMemory()
//package com.java2s; /*/*from w ww . j a v a2 s . c om*/ // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // // Copyright (C) 2001-2005 Julian Hyde // Copyright (C) 2005-2012 Pentaho and others // All Rights Reserved. */ public class Main { public static String printMemory() { return printMemory(null); } public static String printMemory(String msg) { final Runtime rt = Runtime.getRuntime(); final long freeMemory = rt.freeMemory(); final long totalMemory = rt.totalMemory(); final StringBuilder buf = new StringBuilder(64); buf.append("FREE_MEMORY:"); if (msg != null) { buf.append(msg); buf.append(':'); } buf.append(' '); buf.append(freeMemory / 1024); buf.append("kb "); long hundredths = (freeMemory * 10000) / totalMemory; buf.append(hundredths / 100); hundredths %= 100; if (hundredths >= 10) { buf.append('.'); } else { buf.append(".0"); } buf.append(hundredths); buf.append('%'); return buf.toString(); } }