Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By specifying an initial size for the <code>ArrayList</code> you're reserving space for <em>references</em> to the elements, not the elements themselves. Each time you call <code>add()</code>, a new <code>Integer</code> object is created and added to the underlying array, and it's most likely these objects that are eating up your heap.</p> <p>I'm a little surprised that just adding -Xms300m helped - this sets the <em>minimum</em> heap size, but without also setting the <em>maximum</em> (with -Xmx) you'd normally see an error:</p> <pre><code>$ java -Xms300m blah Error occurred during initialization of VM Incompatible minimum and maximum heap sizes specified </code></pre> <p>When a Java app creates lots of objects and approaches the heap limit, the JVM starts to perform garbage collection (GC), which essentially involves two steps:</p> <ul> <li>hunting for objects that are no longer in use and can be freed up</li> <li>consolidating objects that have been around for a while into a different part of the heap (the "old" or "tenured generation") - this means that future GC runs can ignore these objects, improving performance</li> </ul> <p>There's lots of in-depth documentation on Java's GC mechanisms (including the <a href="http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html" rel="nofollow">daddy of them all</a>) but for starters, to see what's happening in your program try adding the <code>-verbose:gc</code> flag. This outputs a line each time the garbage collector kicks in, telling you how long it took to run and how much memory was freed up, which might give you clues as to what's happening in the heap when you increase the number of iterations.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload