Yet another example on getting & printing free memory, max memory, total memory details in the output using Runtime class.
Example
class MemoryDetails
{
public static void main(String args[])
{
// Create Runtime object
Runtime r=Runtime.getRuntime();
// Free memory in JVM
System.out.println("Free memory: "+r.freeMemory());
// Total memory in JVM
System.out.println("Total memory: "+r.totalMemory());
// Max memory JVM uses
System.out.println("Max memory: "+r.maxMemory());
}
}
Output
Free memory: 15948296
Total memory: 16252928
Max memory: 259522560
Note: Memory is given in the form of bytes.
No comments:
Post a Comment