[R] Memory hungry routines
ALBERTO VIEIRA FERREIRA MONTEIRO
albmont at centroin.com.br
Mon Dec 29 19:52:05 CET 2014
Is there any way to detect which calls are consuming memory?
I run a program whose global variables take up about 50 Megabytes of
memory, but when I monitor the progress of the program it seems to
allocating 150 Megabytes of memory, with peaks of up to 2 Gigabytes.
I know that the global variables aren't "copied" many times by the
routines, but I suspect something weird must be happening.
Alberto Monteiro
PS: the lines, below, count the memory allocated to all global
variables, probably it could be adapted to track the local variables:
y <- ls(pat="") # get all names of the variables
z <- rep(0, length(y)) # create array of sizes
for (i in 1:length(y)) z[i] <- object.size(get(y[i])) # loop: get all
sizes (in bytes) of the variables
# BTW, is there any way to vectorialize the above loop?
xix <- sort.int(z, index.return = TRUE) # sort the sizes
y <- y[xix$ix] # apply the sort to the variables
z <- z[xix$ix] # apply the sort to the sizes
y <- c(y, "total") # add a totalizator
z <- c(z, sum(z)) # sum them all
cbind(y, z) # ugly way to list them
More information about the R-help
mailing list