Java Utililty Methods Memory Used

List of utility methods to do Memory Used

Description

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

Method

intgetUsedMemory()
Returns the current amount of memory (in MB) this JVM is using.
return getAllocatedMemory() - getFreeMemory();
longgetUsedMemory()
get Used Memory
Runtime rt = Runtime.getRuntime();
long usedMB = (rt.totalMemory() - rt.freeMemory()) / 1024 / 1024;
return usedMB;
longgetUsedMemory()
get Used Memory
Runtime runtime = Runtime.getRuntime();
return runtime.totalMemory() - runtime.freeMemory();
longgetUsedMemory()
get Used Memory
final Runtime runtime = Runtime.getRuntime();
final long freeBytes = runtime.freeMemory();
final long totalBytes = runtime.totalMemory();
return totalBytes - freeBytes;
longgetUsedMemory()
get Used Memory
return (getMaxMemory() - getFreeMemory());
intgetUsedMemory()
get Used Memory
return (int) (Runtime.getRuntime().totalMemory() / 1024);
StringgetUsedMemory()
Returns a string which describes the amount of memory currently used by the JVM heap.
final Runtime runtime = Runtime.getRuntime();
return "Used memory: " + String.valueOf((runtime.totalMemory() - runtime.freeMemory()) / MEGA) + " MB";
doublegetUsedMemory()
Gets the memory used by the JVM in MB.
Runtime rt = Runtime.getRuntime();
long memLong = rt.totalMemory() - rt.freeMemory();
double memDouble = memLong / (1024.0 * 1024.0);
memDouble = Math.round(memDouble * 100) / 100.0;
return memDouble;
longgetUsedMemory()
get Used Memory
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
longgetUsedMemory()
Return the number of memory bytes used, which is computed by subtracting the 'free' memory from 'total' memory.
long total = Runtime.getRuntime().totalMemory();
long free = Runtime.getRuntime().freeMemory();
return total - free;