title: Unexpectedly-high memory usage from data.table::frollmean()
body: <p>I have a data table of 20M rows and 20 columns, to which I apply vectorized operations that return lists, themselves assigned by reference to additional columns in the data table.</p>
  <p>The memory usage increases predictably and modestly throughout those operations, until I apply the (presumably highly efficient) <code>frollmean()</code> function to a column that contains lists of length 10 using an adaptive window. Running even the much smaller RepRex in R 4.1.2 on Windows 10 x64, with package <code>data.table</code> 1.14.2, the memory usage spikes by ~17GB when executing <code>frollmean()</code>, before coming back down, as seen in Windows' Task Manager (Performance tab) and measured in the <code>Rprof</code> memory profiling report.</p>
  <p>I understand that <code>frollmean()</code> uses parallelism where possible, so I did set <code>setDTthreads(threads = 1L)</code> to make sure the memory spike is not an artifact of making copies of the data table for additional cores.</p>
  <p>My question: <strong>why is <code>frollmean()</code> using so much memory relative to other operations, and can I avoid that?</strong></p>
  <h2>RepRex</h2>
  <pre><code>library(data.table)
  set.seed(1)
  setDTthreads(threads = 1L)
  
  obs   &lt;- 10^3 # Number of rows in the data table
  len   &lt;- 10   # Length of each list to be stored in columns
  width &lt;- c(seq.int(2), rep(2, len - 2)) # Rolling mean window
  
  # Generate representative data
  DT &lt;- data.table(
    V1 = sample(x =  1:10, size = obs, replace = TRUE),
    V2 = sample(x = 11:20, size = obs, replace = TRUE),
    V3 = sample(x = 21:30, size = obs, replace = TRUE)
  )
  
  # Apply representative vectorized operations, assigning by reference
  DT[, V4 := Map(seq, from = V1, to = V2, length.out = len)] # This is a list
  DT[, V5 := Map(&quot;*&quot;, V4, V3)] # This is a list
  DT[, V6 := Map(&quot;*&quot;, V4, V5)] # This is a list
  
  # Profile the memory usage
  Rprof(memory.profiling = TRUE)
  
  # Rolling mean
  DT[, V7 := frollmean(x = V6, n = width, adaptive = TRUE)]
  
  # Report the memory usage
  Rprof(NULL)
  summaryRprof(memory = &quot;both&quot;)
  </code></pre>