Why does the amount of used heap decrease when the heap size increases?
<p>I'm reading a large text file into an ArrayDeque,</p>

<pre><code>    BufferedReader br = new BufferedReader(new FileReader(fname));
    String line=null;
    //allocate an ArrayDeque with enough room for 50M lines.
    ArrayDeque&lt;String[]&gt; inMemory = new ArrayDeque&lt;String[]&gt;(50000000);
    while((line=br.readLine())!=null){
        String[] lineArr = line.split("\t");
        inMemory.add(lineArr);
    }
    br.close();
</code></pre>

<p>I run it with</p>

<pre><code>java -server -Xmx128g -cp target/stackoverflowquestion-1.0-SNAPSHOT-jar-with-dependencies.jar com.stackoverflow.Question
</code></pre>

<p>While I run the code I open up <a href="http://visualvm.java.net/" rel="nofollow">visualvm</a> and watch how the memory gets used up:</p>

<p><img src="http://i.stack.imgur.com/GGXiQ.png" alt="visualvm"></p>

<p>Why does the amount of used heap periodically decrease?</p>

<p><strong>edit:</strong> I changed the String[] to String. Now it does not happen. The lineArrs don't go away on each loop iteration.</p>

<pre><code>BufferedReader br = new BufferedReader(new FileReader(fname));
String line=null;
//allocate an ArrayDeque with enough room for 50M lines.
ArrayDeque&lt;String&gt; inMemory = new ArrayDeque&lt;String&gt;(50000000);
while((line=br.readLine())!=null){
    inMemory.add(line);
}
br.close();
</code></pre>

<p><img src="http://i.stack.imgur.com/LjOf7.png" alt="enter image description here"></p>
