Garbage Collection in R
<p>I started to use <code>gc()</code> for garbage collection in R. I have 16 GB RAM and sometimes, up to 10 GB RAM gets freed when using this command.</p>

<p>Does it make sense to use <code>gc()</code> inside functions? Often, the functions I write/use need almost all RAM that is available. Or does R <em>reliably</em> clean up memory that was used only inside a function?</p>

<p>Example:</p>

<pre><code>f &lt;- function(x) {
  # do something
  y &lt;- doStuff(x)

  # do something else
  z &lt;- doMoreStuff(y)

  # garbage collection
  gc()

  # return result
  return(z)
}
</code></pre>