title: Memory leaks in R when using a ~ operator
body: <p>I am following the examples from <a href="http://adv-r.had.co.nz/memory.html" rel="nofollow noreferrer">http://adv-r.had.co.nz/memory.html</a>. In one of the examples a function of the following form is proposed (after loading the package <em>pryr</em>):</p>
  <pre><code>f2 &lt;- function() {
    x &lt;- 1:1e6
    z ~ x
  }
  mem_change(y &lt;- f2())
  object_size(y)
  </code></pre>
  <p>in this case, I can see that memory is not released because the value of <em>mem_change</em> includes the memory space of vector <em>x</em>.</p>
  <p>I tried the following function where I delete the vector <em>x</em> explicitly and here I can see that mem_change doesn't include the memory for <em>x</em>:</p>
  <pre><code>f3 &lt;- function() {
    x &lt;- 1:1e6
    z ~ x
    rm(x)
  }
  mem_change(y &lt;- f3())
  object_size(y)
  </code></pre>
  <p>what I don't know is what the operator <em>~</em> is actually doing in the first function and regarding the second function, is that the proper way to release memory inside a function?</p>
  <p>Thanks</p>