Java Utililty Methods Memory Usage

List of utility methods to do Memory Usage

Description

The list of methods to do Memory Usage are organized into topic(s).

Method

StringgetMemoryUsage()
get Memory Usage
String result = "free: " + format(Runtime.getRuntime().freeMemory());
result += ", max: " + format(Runtime.getRuntime().maxMemory());
return result;
doublegetMemoryUsage()
Return the Difference (in MegaBytes) between the first sampled free memory and current free memory
long diff = startMemory - Runtime.getRuntime().freeMemory();
return ConvertByteToMegaByte(diff);
StringgetMemoryUsage()
get Memory Usage
return ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / MB) + "/"
        + (Runtime.getRuntime().totalMemory() / MB) + "/" + (Runtime.getRuntime().maxMemory() / MB + " Mb");
longgetMemoryUsage()
get Memory Usage
return getTotalMemory() - getFreeMemory();
StringgetMemoryUsage()
get Memory Usage
Runtime rt = Runtime.getRuntime();
long total = rt.totalMemory() / (1024 * 1024);
long free = rt.freeMemory() / (1024 * 1024);
return String.format("Used: %d MB, Free: %d MB, Total: %d MB", total - free, free, total);
longgetMemoryUsage()
get Memory Usage
takeOutGarbage();
long totalMemory = Runtime.getRuntime().totalMemory();
takeOutGarbage();
long freeMemory = Runtime.getRuntime().freeMemory();
return (totalMemory - freeMemory);
longgetMemoryUsage()
Returns the amount of memory currently used by the JVM.
hardClean();
return runtime.totalMemory() - runtime.freeMemory();
StringgetMemoryUsage()
Report memory usage, including used memory, free memory, total memory, and the maximum memory allotable to the JVM
Runtime rt = Runtime.getRuntime();
long max = rt.maxMemory();
long total = rt.totalMemory();
long free = rt.freeMemory();
return String.format("Memory used: %s, free: %s, total: %s, max: %s", formatMemory(total - free),
        formatMemory(free), formatMemory(total), formatMemory(max));
longgetMemoryUsage()
get Memory Usage
return runtime.totalMemory() - runtime.freeMemory();
longgetMemoryUsage()
Gets memory usage, in MB
long memory = Runtime.getRuntime().totalMemory();
return Math.round(memory / Math.pow(2, 20));