[R] Cannot allocate large vectors (running out of memory?)

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Mar 24 23:12:08 CET 2008


See ?"Memory-limits" and rw-FAQ Q2.9.  Since you have already used more 
than 1Gb of what is presumably a 2Gb address space (we don't know your 
Windows version), it is not surprising that there is no 285Mb hole left.

On Mon, 24 Mar 2008, Ronnen Levinson wrote:

>
>   Hi.
>   As shown in the simplified example below, I'm having trouble allocating
>   memory for large vectors, even though it would appear that there is more
>   than enough memory available. That is, even with a memory limit of 1500 MB,
>   R 2.6.1 (Win) will allocate memory for a first vector of 285 MB, but not for
>   a second vector of the same size. Forcing garbage collection does not seem
>   to solve the problem.
>   Can anyone explain why is this happening, and how to fix it?
>   Thanks,
>   Ronnen.
>   P.S. E-mailed CCs of posted replies would be appreciated.
>   > rm(list=ls(all=TRUE))
>   > gc()
>            used (Mb) gc trigger  (Mb)  max used  (Mb)
>   Ncells 143465  3.9     350000   9.4    350000   9.4
>   Vcells  88573  0.7   50380943 384.4 131023877 999.7
>   > memory.limit()
>   [1] 1535.875
>   > n <- 8640 * 4320
>   > x=rep(1/3, n)
>   > memory.size()
>   [1] 578.8543
>   > gc()
>              used  (Mb) gc trigger  (Mb)  max used  (Mb)
>   Ncells   143471   3.9     350000   9.4    350000   9.4
>   Vcells 37413375 285.5   78720219 600.6 131023877 999.7
>   > y=rep(1/7, n)
>   Error: cannot allocate vector of size 284.8 Mb
>   > memory.size()
>   [1] 578.8543
>   > gc()
>              used  (Mb) gc trigger  (Mb)  max used  (Mb)
>   Ncells   143471   3.9     350000   9.4    350000   9.4
>   Vcells 37413375 285.5   78720219 600.6 131023877 999.7
>   > version
>                  _
>   platform       i386-pc-mingw32
>   arch           i386
>   os             mingw32
>   system         i386, mingw32
>   status
>   major          2
>   minor          6.1
>   year           2007
>   month          11
>   day            26
>   svn rev        43537
>   language       R
>   version.string R version 2.6.1 (2007-11-26)
>
>   --
>   Ronnen Levinson, Ph.D.
>   scientist, Lawrence Berkeley National Lab
>   The  Onion  horoscope:  Pisces February 19 - March 20 You will soon be
>   unwillingly forced into a flurry of activity when you are chosen to host the
>   2014 Winter Olympiad.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
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