Should I reset Java heap space maximum after use?
<p>I'm working with some modeling algorithms in R, one of which runs in Java (<a href="https://cran.r-project.org/web/packages/bartMachine/bartMachine.pdf" rel="nofollow noreferrer">bartMachine</a>). I've found that with the size of my data I need to increase the maximum heap space for java before running the modeling algorithm.</p>

<p>I'm doing this like so: </p>

<p><code>options(java.parameters = "-Xmx16g")</code></p>

<p><strong>My question is, do I need to reset the heap space afterwards, if no other algorithm is going to be using java (or at least that much heap space)? Or will the memory allocated to java be reclaimed as needed with no performance loss?</strong></p>

<p>I've already searched around some on the subject, and I understand <em>how</em> to change/lower the heap space. I also understand that R/Java will do garbage collection to remove old objects from memory to free more space.</p>

<p>What I don't understand is how changing the heap space affects the memory available for other programs, and whether it is necessary or even a good idea in this case to alter the heap size post-use.</p>

<p>Some of the answers/resources I've already looked at:</p>

<p><a href="https://stackoverflow.com/questions/4952568/is-there-a-way-to-lower-java-heap-when-not-in-use">Is there a way to lower Java heap when not in use?</a></p>

<p><a href="https://stackoverflow.com/questions/1582209/java-garbage-collector-when-does-it-collect">Java garbage collector - When does it collect?</a></p>

<p><a href="http://www.bramschoenmakers.nl/en/node/726" rel="nofollow noreferrer">http://www.bramschoenmakers.nl/en/node/726</a></p>

<p><a href="https://cran.r-project.org/web/packages/bartMachine/bartMachine.pdf" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/bartMachine/bartMachine.pdf</a></p>