Here you can find the source of getConsumedMemory(boolean preRunGarbageCollector)
public static long getConsumedMemory(boolean preRunGarbageCollector)
//package com.java2s; //License from project: Open Source License public class Main { public static long getConsumedMemory(boolean preRunGarbageCollector) { Runtime rt = getRuntimeAndRunGC(preRunGarbageCollector); return bytesToMegabytes(rt.totalMemory() - rt.freeMemory()); }/*from w ww.ja va 2s . com*/ private static Runtime getRuntimeAndRunGC(boolean preRunGarbageCollector) { Runtime rt = Runtime.getRuntime(); if (preRunGarbageCollector) { //long startTime = System.currentTimeMillis(); //DEBUG rt.gc(); //System.out.println("GC takes "+(System.currentTimeMillis()-startTime)+" ms."); //DEBUG } return rt; } private static long bytesToMegabytes(long bytes) { long MEGABYTE = 1024L * 1024L; return bytes / MEGABYTE; } }