[R] how to free memory space ??

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Apr 16 15:17:57 CEST 2004


On Fri, 16 Apr 2004, Jeff Gentry wrote:

> > I thought that 'rm' function would free the memory used for the
> > deleted object, but it doesn't seem to be the case, as I don't observe
> > any change in the allocated memory for R in the windows task manager.

That is never a good test of how much is actually allocated.  Windows is 
not good at taking back memory, and in any case R for Windows avoids 
offering it back as that is slow if it needs it again.  So memory can be 
reserved for R but not actually allocated.

> > I ask this question because sometimes I have encounter a '... ran out
> > of memory' error - for a calculation that previously worked fine - I
> > did notice that this error often occurs when other objects are using a
> > lot of memory. Closing/relaunching R and redoing the calculation helps
> > under these circumstances.....
> 
> gc() will reclaim memory from objects which are no longer being used.

Yes, but that is done automatically before such error messages are 
produced.

The real issue is that Windows has a single 2Gb (or 3Gb on some versions) 
memory space, and it can get fragmented.  Having free memory does not help 
if it is not in a large enough contiguous chunk, and even if it is, it may 
not be accessible to the memory manager used.

You should find 1.9.0 works better under Windows, so please upgrade if
you have not done so already.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list