Edit 3:
I created a much shorter example of the memory leak. I hope it makes it much easier to reason about what's going on. As the iterations proceed, you see steadily increasing gc() VCell memory use, while memory use reported by tables() stays the same. Somehow, the unlist(.SD) call seems to be responsible. Here it is:
DT = data.table(k = 1:100, g = 1:20, val = rnorm(2e6))
for (i in 1:100){
tmp = DT[ , unlist(.SD), by = 'k']
print(gc())
tables()
}
Original post:
I am seeing some memory behavior I don't understand when using the data.table package. I am using R-2.13.0 with data.table 1.8.8. I run on 64-bit suse linux.
My ultimate objective is to reshape a data.table from "long" to "wide" format using as little memory as possible. I followed a suggestion in another [SO post] ( Nested if else statements over a number of columns). Basically I try to reshape a data.table returning a named list in the j expression.
I see a steadily increasing memory use, which seems like a memory leak. The total memory used by data.tables or other objects does not account for what is shown in gc(). in particular, Vcells starts at around 17 MB and ends at nearly 30 MB, while the total memory use reported by tables() is 19 MB (at the end). There are no other objects (that I can see) using any meaningful amount of memory. Running the code below repeatedly shows the increasing memory use with print(gc()) statements.
Am I missing something or is there an issue with some of the memory allocation in dogroups.c ?
Here is code to reproduce the problem I see. Any ideas? I really would like to be able to reshape a data.table relatively efficiently, with memory use being a bigger consideration than speed.
library(data.table)
if(!exist