Saturday, August 4, 2007

How to get free available memory in Java program

Continuing with our interest for java, I decided to write something about getting free avaialble memory in Java program. Below, i am putting the code snippet which will print the total and free memory at runtime to the console.

public class MemoryExp {
public static void main(String[] args) { System.out.println(”Total Memory”+Runtime.getRuntime().totalMemory()); System.out.println(”Free Memory”+Runtime.getRuntime().freeMemory());
}

}
Cheers,
Vaibhav Pandey

No comments: