[R] R Memory Issues

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Oct 10 14:32:01 CEST 2001

On Wed, 10 Oct 2001, carl mela wrote:

> I am running R code (version 1.3.1) on a PC with 650 Mb of RAM, and
> after a number of iterations of the code (each iteraction corresponds to
> a set of draws in an MCMC algorithm), the program runs out of memory
> (however, the number of iterations before the code runs out of memory is
> quite variable).
> After each iteration in the code, I run the following lines to ascertain
> the memory demanded by R:
> z_sapply(ls(), function(x) object.size(get(x)))
> totmem_sum(as.matrix(rev(z)))
> print ("totmem")
> print (totmem)
> Interestingly, the total size of all of the objects does not increase
> with each iteration, as the objects are overwritten from iteration to
> iteration.  So, for some reason R is consuming more memory each
> iteration, even though the objects do not increase in size.  I have even
> tried to issue a gc() command after each iteration, but this does not
> help.

There are much better ways to see the real memory usage. gc() for a start,
and on Windows see ?memory.size.

You may well be suffering from the way Windows manages memory: it is
entirely possible that it is not running out of memory, just fragmenting
it so it cannot allocate the chunks you want.

I suggest you re-compile R reserving a much larger initial chunk of memory
(RESERVED_SIZE in src/gnuwin32/malloc.c: set it above your RAM size) and
see if this helps.

> I would appreciate any advice from those on this list-serv regarding how
> to solve this problem.  Thanks.

Next time please report exactly what messages you got!

> --
> Carl F. Mela
> Associate Professor of Marketing
> Fuqua School of Business
> Duke University
> 134 Tower View Drive, Box 90120
> Durham, North Carolina 27708-9012
> Phone: 919-660-7767
> Fax: 919-681-6245
> Email: mela at duke.edu
> Web: http://faculty.fuqua.duke.edu/~mela/bio

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list