title: Generate java dump when OutOfMemory
body: <p>I have a program that should eventually generate <code>OutOfMemory</code> .
  The program code is:</p>
  
  <pre><code>public class VeryLargeObject implements Serializable {
      public static final int SIZE = 1 &lt;&lt; 12;
  
      public String tag;
      public int[][] bigOne = new int[SIZE][SIZE];
  
      {
          // Initialize bigOne
          for(int i = 0; i &lt; SIZE ; ++i) {
              for(int j = 0; j &lt; SIZE; ++j) {
                  bigOne[i][j] = (int) (Math.random() * 100);
              }
          }
      }
  
      public VeryLargeObject(String tag) {
          this.tag = tag;
      }
  
      public static void main(String args[]) {
          VeryLargeObject[] vla = new VeryLargeObject[1 &lt;&lt; 12];
          for(int i = 0; i &lt; Integer.MAX_VALUE; ++i) {
              vla[i] = new VeryLargeObject("aa");
          }
      }
  }
  </code></pre>
  
  <p>I run the program with the following parameters:</p>
  
  <pre><code>java VeryLargeObject -Xms1024m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="D:\workspace"
  </code></pre>
  
  <p><strong>The program fails with OutOfMemory but no dump file is generated . Do you have any idea why?</strong></p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
          at VeryLargeObject.&lt;init&gt;(VeryLargeObject.java:14)
          at VeryLargeObject.main(VeryLargeObject.java:32)
  </code></pre>