Java heap growth
<p>I'm developing a desktop java application and am trying to optimize memory usage at runtime, using Java visualVM.</p>

<p>The thing is that I've noticed that my used heap is growing about 1mb/s and I'm trying to find out what's causing it. This is what it looks like:</p>

<p><a href="https://i.stack.imgur.com/06dD6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/06dD6.png" alt="enter image description here"></a></p>

<p>First of all, I've noticed that the JVM seems to be allocating quite a lot of memory at runtime by itself. I've tried to make a dummy program that just sleeps and the increase in used heap seemed to be about 0.2Mb/s.</p>

<p>However, My application obviously allocates more. And I know I'm creating quite a lot of objects at runtime, but it shouldn't be close to MBs/s, more like bytes/second.</p>

<p>So, I've made a few dumps and compared them. Here's the first, when a fresh GC has been invoked:</p>

<p><a href="https://i.stack.imgur.com/Zgf7h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zgf7h.png" alt="enter image description here"></a></p>

<p>And here's the other, where the used heap has grown ~100MB:</p>

<p><a href="https://i.stack.imgur.com/bb71t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bb71t.png" alt="enter image description here"></a></p>

<p>Here's the comparison:</p>

<p><a href="https://i.stack.imgur.com/LB8lZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LB8lZ.png" alt="enter image description here"></a></p>

<p>Now, what's confusing me is that I can't find any trace of the additional 100 mb in the two dumps.</p>

<p>Total bytes are the same. Classes are the same. Instances are about the same. And the comparison gives me no hints. The dumps, however, confirms that I'm only allocating a handful of classes/s. So what gives?</p>

<p>Update 1: Using the eclipse memory manager:</p>

<p><a href="https://i.stack.imgur.com/kG8oh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kG8oh.png" alt="enter image description here"></a></p>

<p>(The suspects aren't culprits). And I'd like to stress that visualVM showed me a 100MB difference in used heap at the time of the dumps. My in-application </p>

<pre><code>print("Used Mbs: " + (r.totalMemory() - r.freeMemory())/mb);
</code></pre>

<p>Also confirmed this. ('r' is a Runtime instance)</p>