title: finding cause of excessive memory usage in jvm 8
body: <p>My actual problem is this, currently netbeans is using about 4G (according to Activity Monitor on OS X) of memory. I've set several memory limiting options to no avail. from my <code>netbeans.conf</code></p>
  
  <pre><code>netbeans_default_options="-J-client -J-Xmx1G -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxMetaspaceSize=256m -J-XX:+UseConcMarkSweepGC -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"
  </code></pre>
  
  <p>what I'd like to know is how can I find out why it's using this much memory? what steps should I take to determine the root source of the problem.</p>
  
  <p>(I'm more interested in the generic than specifically netbeans). It may be worth noting that I've only been programming Java for a few months and don't know the tools available for this, or what things I should be checking for. (e.g. I added the MaxMetaspaceSize today because I realized that wasn't being limited, thinking that was probably it, but I'm still not sure how to check).</p>
  
  <p>Here are some things I've found out from a visualvm heap dump</p>
  
  <pre><code>  File size: 364.7 MB      Total bytes: 332,921,516     Total classes: 24,143     Total instances: 4,151,139     Classloaders: 3,272     GC roots: 65,185     Number of objects pending for finalization: 0 
  </code></pre>
  
  <p>it's metaspace graph showed it had reserved approximately 600M for the heap and 150M for metaspace. At that time Activity monitor was showing about 2G Memory usage. What I'm trying to figure out is where the entire 1G extra of memory usage is. If it were a few hundred more Megabytes it'd be tolerable, but 2-4G of ram is half the system memory (also noting that it doesn't behave this way on my Linux box, with the same versions). I'd think that anywhere from 800M-2G would probably be normal for a java IDE, and would be tolerable, and I wouldn't be investigating, it's this, use the rest of available memory, without any perceivable cause that makes me want to see what exactly, and why it's reserving this.</p>
  
  <p><img src="https://i.stack.imgur.com/awgww.png" alt="Activity Monitor and visual VM numbers not adding up"></p>
  
  <p><strong>Update:</strong> this is a <a href="https://bugs.openjdk.java.net/browse/JDK-8041572" rel="nofollow noreferrer">Memory leak in Swing on OS X in JVM 8 </a> I can't really accept answer that couldn't have gotten me to the point of locating the cause of the problem in jdk 8.</p>