Here you can find the source of memory()
public static String memory()
//package com.java2s; /**/*from w w w . j av a2 s . c om*/ * Copyright (C) 2009 G?nter Ladwig (gla at aifb.uni-karlsruhe.de) * * This file is part of the graphindex project. * * graphindex is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 * as published by the Free Software Foundation. * * graphindex is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with graphindex. If not, see <http://www.gnu.org/licenses/>. */ public class Main { public static String memory() { Runtime r = Runtime.getRuntime(); long max = r.maxMemory() / 1000; return "memory (used/free/max): " + (max - freeMemory()) / 1000 + "/" + freeMemory() / 1000 + "/" + r.maxMemory() / 1000000; } public static long freeMemory() { Runtime r = Runtime.getRuntime(); return (r.freeMemory() + (r.maxMemory() - r.totalMemory())) / 1000; } }