Here you can find the source of memory()
public static long memory()
//package com.java2s; //License from project: Open Source License public class Main { /**//from www . ja v a 2s .c o m * return used memory * @return */ public static long memory() { long m = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); return m; } public static float memory(String format) { if (format.equals("mb")) { long m = memory(); return (float) (m / 1024.0 / 1024.0); } else { return (float) memory(); } } }