List of utility methods to do Memory Used
long | calcUsedMemorySize() calculate used memory size. return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
|
void | disposeUnusedMemory() Freeing memory that is available for the application by running the garbage collector. Runtime.getRuntime().gc(); |
long | getAvailableUnusedMemory() Find out how much unused memory (in bytes) is still available for the JVM to use. Runtime r = Runtime.getRuntime();
return r.maxMemory()
- r.totalMemory()
+ r.freeMemory();
|
int | getMemoryInUse() Returns the number of megabytes (MB) of memory in use. Runtime runtime = Runtime.getRuntime(); long mb = 1024 * 1024; long total = runtime.totalMemory(); long free = runtime.freeMemory(); return (int) ((total - free) / mb); |
long | getMemoryUse() retrieve the usage of memory. putOutTheGarbage(); long totalMemory = Runtime.getRuntime().totalMemory(); putOutTheGarbage(); long freeMemory = Runtime.getRuntime().freeMemory(); return (totalMemory - freeMemory); |
long | getMemoryUsed() get Memory Used return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
|
int | getMemoryUsed() get Memory Used int mb = 1024 * 1024; Runtime runtime = Runtime.getRuntime(); int memoryUsed = (int) ((runtime.totalMemory() - runtime.freeMemory()) / mb); return memoryUsed; |
int | getMemoryUsed() Get the used memory in KB. collectGarbage(); Runtime rt = Runtime.getRuntime(); long mem = rt.totalMemory() - rt.freeMemory(); return (int) (mem >> 10); |
long | getMemoryUsedBytes() get Memory Used Bytes final Runtime runtime = Runtime.getRuntime(); return runtime.totalMemory() - runtime.freeMemory(); |
String | getMemoryUsege() get Memory Usege return String.format("memory={total: %d MB, free: %d MB, used: %d MB, max: %d MB}", (Runtime.getRuntime().totalMemory() / 1000 / 1000), (Runtime.getRuntime().freeMemory() / 1000 / 1000), ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 / 1000), (Runtime.getRuntime().maxMemory() / 1000 / 1000)); |