title: Is there a way to lower Java heap when not in use?
body: <p>I'm working on a Java application at the moment and working to optimize its memory usage. I'm following the guidelines for proper garbage collection as far as I am aware. However, it seems that my heap seems to sit at its maximum size, even though it is not needed.</p>
  
  <p>My program runs a resource intensive task once an hour, when the computer is not in use by a person. This task uses a decent chunk of memory, but then frees it all immediately after the task completes. The NetBeans profiler reveals that memory usage looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/YC2cf.png" alt="Java program memory usage"></p>
  
  <p>I'd really like to give all of that heap space back to the OS when not in use. There is no reason for me to hog it all while the program won't even be doing anything for at least another hour.</p>
  
  <p>Is this possible? Thanks.</p>