I have the following class in Java :
public class MemoryUsage
{
public static void main(String[] args)
{
Vector v = new Vector();
while (true)
{
byte b[] = new byte[1048576];
try {
Thread.sleep(200);
} catch (InterruptedException ie){}
v.add(b);
Runtime rt = Runtime.getRuntime();
System.out.println( "free memory: " + rt.freeMemory() );
}
}
public void showCurrentTime()
{
long time = System.currentTimeMillis();
System.out.println(time);
}
}
And I want to limit how much memory can be used by this program. I tried to set an initial and maximum size (from command-line), like follows :
C:\JMX_code\Memory_test>java -Xms2m -Xmx4068M MemoryUsage
Error occurred during initialization of VM
The size of the object heap + VM data exceeds the maximum representable size
But this doesn't work. How do I figure out what is my own maximum heap size ?
My Java version info. is as follows :
Java(TM) SE Runtime Environment (build 1.7.0_02-b13) Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)