title: JPype / Java - Initialize with, or get, remaining heap space
body: <p>We have software written in Python, which uses JPype to call Java, which performs various resource heavy calculations / report building. We originally assigned 800mb of heap space when starting the JVM. The java side is fully multithreaded and will work with whatever resources are available to it.</p>
  
  <pre><code>jvmArgs = ["-Djava.class.path=" + classpath, "-Xmx800M"]
  jpype.startJVM(u"java\\jre8\\bin\\client\\jvm.dll", *jvmArgs)
  </code></pre>
  
  <p>This worked well until we tested on Windows XP for our legacy clients. The new machines are Win 7 64-bit with 4GB of RAM, whereas the old ones are Win XP 32-bit with only 2 GB of ram.</p>
  
  <p>The issue is that JPype causes our application to ungracefully and silently crash if we allocate too much memory. A try catch doesn't even get triggered on the statement above.</p>
  
  <p>I'm wondering if there's a way to use java from command line to determine how much memory we can allocate on a computer. We can check if it's 32-bit or 64-bit which helps, but we need to make sure they aren't running other programs taking up heap space on the JVM. If they are, our application will crash.</p>
  
  <p>Reader's Digest: We'd like to allocate 500mb of heap space when initializing the JVM, but can't be sure of how much space is currently being used. If we allocate too much, the entire application silently crashes.</p>
  
  <p>We use the following
  JPype: 0.5.4.2
  Python: 2.7
  Java: 1.8 or 1.7 (64-bit or 32-bit)</p>
  
  <p>Thanks.</p>