FAQ

Java

JSP

Servlet


Advertisement



How to get memory information in Java program?

In Java, memory is allocated in various places such as the stack, heap, etc. While your application is running, you can sniff out the memory using: Runtime.getRuntime().freeMemory() and Runtime.getRuntime().totalMemory().

public class Program {

public static void main(String... args) {
System.out.println("Max Memory : " +
 Runtime.getRuntime().maxMemory());
System.out.println("Total Memory : " +
 Runtime.getRuntime().totalMemory());
System.out.println("Free Memory : " +
Runtime.getRuntime().freeMemory());
}
}


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |