1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Get Free Memory of Java Virtual Machine(JVM) Example This Java example shows how to get amount of free memory in the Java Virtual Machine(JVM) using freeMemory method of Java Runtime class. */ public class GetFreeMemory { public static void main(String args[]) { /* * get current Java Runtime using getRuntime() * method of Runtime class. */ Runtime runtime = Runtime.getRuntime(); /* * To determine amount of free memory available to current * Java Virtual Machine(JVM), use * * long freeMemory() * method of Runtime class. */ long freeMemory = runtime.freeMemory(); System.out.println(freeMemory + " bytes free in JVM"); } } /* Typical output would be 4993048 bytes free in JVM */ |
Add Comment