I have BEA JRockit JDK 5.0 Update 6 running on Windows XP. I wish to know what is the max heap I can allocate when I have primary memory of 4GB on my machine.
A:
I don't have JRockit but I should try some values of -Xmx
option.
On my JVM the limit is 1610 MB:
c:\tmp>java -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
c:\tmp>java -Xmx1610m mem_test
1552 MB Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at mem_test.main(mem_test.java:15)
c:\tmp>java -Xmx1611m mem_test
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
I tested it with such program, so you can see how many memory you application can allocate from heap available to JVM:
import java.util.ArrayList;
import java.io.*;
class mem_test
{
public static void main(String[] args)
{
ArrayList<byte[]> big_list = new ArrayList<byte[]>();
int max = 0;
int i = 0;
while (true)
{
++i;
big_list.add(new byte[1024 * 1024]);
max = i;
if (i % 16 == 0)
System.out.print("\r" + i + " MB ");
}
}
}
Michał Niklas
2010-01-21 12:33:52