How do I know the memory size in virtual machine?
If you want to know the free memory, and the total memory available in the Java runtime environment then you can use the following code snippet to check. package org.kodejava.lang; public class MemoryExample { public static void main(String[] args) { long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); System.out.println("Free Memory = " + freeMemory); System.out.println("Total […]
Article by Wayan · Source: Kode Java ↗
If you want to know the free memory, and the total memory available in the Java runtime environment then you can use the following code snippet to check.
package org.kodejava.lang;
public class MemoryExample {
public static void main(String[] args) {
long freeMemory = Runtime.getRuntime().freeMemory();
long totalMemory = Runtime.getRuntime().totalMemory();
System.out.println("Free Memory = " + freeMemory);
System.out.println("Total Memory = " + totalMemory);
}
}
Here is the result of the code snippet above:
Free Memory = 1018439896
Total Memory = 1029177344
Comments 0
Share your questions, experiences, or feedback about this article.
Sign in with Google to leave a comment.
Sign in with Google
No comments yet. Be the first to share your feedback.