I currently print out memory usage information in my application with the following code:
Runtime runtime = Runtime.getRuntime();
NumberFormat format = NumberFormat.getInstance();
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
errorLog.warn("free memory: " + format.format(freeMemory / 1024));
errorLog.warn("allocated memory: " + format.format(allocatedMemory / 1024));
errorLog.warn("max memory: " + format.format(maxMemory / 1024));
errorLog.warn("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));
The output looks along the lines of the following:
Free Memory: 3,471K
Allocated Memory: 29,572K
Max Memory: 253,440K
Total Free Memory: 227,339K
How does this relate to what I'm seeing in usage from the Task Manager for JVM which is 98,768K?? This is my first time using the Runtime class and checking these values. Looking for possible memory issues in an application that I wrote. I see the Task Mgr value slowly increase over time, but the Runtime class items do not. Though eventually the Task Mgr value will drop dramatically which I guess is the GC running.