title: Java app runs out of heap space at about 1.4GB in a 64 bit OS with -Xmx option set to 4 GB
body: <p>While writing an application that must allocate many objects, I received an exception <code>java.lang.OutOfMemoryError: Java heap space</code>. On reading <a href="https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap">How to deal with “java.lang.OutOfMemoryError: Java heap space” error (64MB heap size)</a> and <a href="https://stackoverflow.com/questions/1596009/java-lang-outofmemoryerror-java-heap-space">java.lang.OutOfMemoryError: Java heap space</a> I tried to run <code>java -jar myJar.jar -Xms1024m -Xmx4096m</code> command, but the application crashes regardless once it allocates about 1.457 GB. This is in 64bit Win XP box. With or w/o -Xmx the moment of crash remains the same in terms of mem usage of java.exe process. Should not a 64 bit application be able to use 4 GB of RAM in a 64 bit OS?</p>