title: How to restrict the memory usage of Java application packed in a jar (-Xmx doesn't seem to work) on Windows
body: <p>I'd want to restrict the maximum heap size for a Java application but it doesn't seem to work. I'm running the application from a jar package through bat in Windows. Bat contents:</p>
  
  <pre><code>@Echo off
  set CLASSPATH=.
  java -Xmx32m -classpath %CLASSPATH% -jar MyApplication.jar
  </code></pre>
  
  <p>This should restrict the maximum heap size of 32 megabytes. However, when I do things consuming memory with the application, the Windows Task Manager shows that the memory consumption goes at least to about 70 megabytes... I even tried with -Xmx2m but that didn't make any difference.</p>
  
  <p>So, I'm not totally sure what's the problem. There is of course stack etc contained in the memory usage but the memory used by the program should be mostly heap space...</p>
  
  <p>Java version seems to be 1.6.0_14.</p>
  
  <p>For those interested what I'm after, I'm trying to see how my application would behave with certain functions when it runs out of heap space.</p>
  
  <p>EDIT: Hmm.. I was surprised that the heap usage was limited to the 32M actually when monitoring with <a href="http://en.wikipedia.org/wiki/JConsole" rel="noreferrer">JConsole</a>. Gotta get more memory used...</p>
  
  <p>Thanks for ideas,
  Touko</p>