[R-sig-Epi] memory over load?

Thomas Lumley tlumley at u.washington.edu
Thu Aug 2 22:39:49 CEST 2007

On Thu, 2 Aug 2007, FZ wrote:

> Hi Thomas,
> My experience in memory management in R is very limited so I am sure you are 
> right, but how do you then explain the following behavior starting with a fresh 
> session?
> memory.size()# 12,000Kb
> x=integer(100000000)
> memory.size() #approx 412,000kb
> rm(x)
> memory.size()#still approx 412,000kb
> gc()
> memory.size()#down to approx 20,000Kb

Yes, running gc() does affect the results of memory.size(), and running it more than once may have an effect, because there are three levels of garbage collection.

However, a highest-level garbage collection is always done before R gives up on allocating memory.  If you run out of memory in R, adding gc() calls to your code will not help. The original question was about running out of memory.


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

More information about the R-sig-Epi mailing list