I am using Eclipse. The problem is my application crashes if the allocated memory is less then 512MB. Now is there anyway to check the available memory for a program before starting heavy memory exhaustive processing? For example, I know we can check available JVM heap size as:
long heapSize = Runtime.getRuntime().totalMemory();
System.out.println("Heap Size = " + heapSize);
Problem is, this gives the JVM heap size. Even increasing it does not work using Eclipse. In Eclipse, if I change the VM arguments then it works. However the printout from above statements is always the same. Is there any command through which I can exactly know how much memory I am allocated for a particular application?
You could use JMX to collect the usage of heap memory at runtime.
Code Example:
Output Example:
If your have question about "Eden Space" or "Survivor Space", check out How is the java memory pool divided