[R] Error cannot allocate vector of size...

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jan 11 12:46:11 CET 2008


Rod wrote:
> On Jan 8, 2008 3:40 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>   
>> On 1/8/2008 8:49 AM, Rod wrote:
>>     
>>> On Jan 8, 2008 12:41 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>>>       
>>>> Rod wrote:
>>>>         
>>>>> Hello,
>>>>>
>>>>> I have a memory problem when I run package WinBUGS with R (2.6.1).
>>>>> Until now I have been using a Pentium IV 3.2Ghz computer with 512Mb of
>>>>> RAM memory (with Windows XP Pro SP2), and I hadn't had any problem.
>>>>> Now I have a new computer with the following characteristics: Intel
>>>>> Core 2 duo 2.33Ghz and 3Gb of RAM memory (with Windows XP Pro SP2) and
>>>>> when I am running the same R syntax I receive the following error
>>>>> message:
>>>>>
>>>>> "Error: cannot allocate vector of size 216.0 Mb".
>>>>>
>>>>> This is an extract of my R syntax:
>>>>>
>>>>>
>>>>>           
>>>>>> memory.limit(4000)
>>>>>>
>>>>>>             
>>>>> NULL
>>>>>
>>>>>           
>>>>>> simu.BYM<-bugs(data, inits, parameters, model.file="Modelo.txt", n.chains=3, n.iter=200000, n.burnin=20000, n.thin=180, debug=FALSE, DIC=FALSE, digits=5, codaPkg=FALSE, bugs.directory="c:/Archivos de programa/WinBUGS14", working.directory=NULL)
>>>>>>
>>>>>>             
>>>>> Error: cannot allocate vector of size 216.0 Mb
>>>>>
>>>>> I have tried:
>>>>> -Change size of virtual memory inside Windows XP
>>>>> -change the R memory settings
>>>>> -run from DOS (R CMD BATCH...)
>>>>> -reviewed the R Windows FAQ and R-Help.
>>>>>
>>>>> but I haven't be able to find a solution !
>>>>>           
>>>> Could you try R-patched?  I recently fixed a minor bug that could have
>>>> symptoms like this. Under certain conditions it would miscalculate the
>>>> amount of available memory.  You can download a copy from
>>>> cran.r-project.org/bin/windows/base/rpatched.html.
>>>>
>>>> Duncan Murdoch
>>>>
>>>>         
>>> Dear Duncan,
>>>
>>> Thank for your advice. But, the patched version produce the same error.
>>>       
>> In that case, you are probably really running out of memory.  It's hard
>> to see why this would happen on the larger machine and not the smaller
>> one, but perhaps the code tries to adapt itself to available resources.
>>   You are likely to have a bit of work diagnosing the problem.
>>
>> The tools to use are memory.size(), memory.limit() (which report on what
>> is available); memory.profile() (which gives more detail on usage).
>> Rprofmem() would also be nice, but it's not enabled in the standard
>> Windows build.
>>
>> Duncan Murdoch
>>
>>     
>
> Dear Duncan,
>
> I have tried to run the same syntax in another pc (with exactly the
> same mark and model as mine) and I have obtained the same error. Then
> we can rule out that it is a problem with the hardware of my pc.
>
> I have tried to change the memory with command --max-mem-size=4000M
> ("c:\...\Rgui.exe" --max-mem-size=4000Mb)  but I obtain this alert:
>
> WARNING: --max-mem-size=4000M: too large and taken as 2047
>   

Windows normally reserves 2 GB for itself.  You can reduce this to 1 GB 
(the method is described in the R Windows FAQ 2.9), but there's no way 
to allocate more than 3 GB to a process in 32 bit Windows.

More below...
> Here I show you the parameters of memory that I obtain before and
> after I run my syntax, and the gc() results obtained during the
> process. Perhaps this values can help you.
>
> thank you,
>
> Rodrigo
>
>
> ############# Memory values before I run the syntax###############
>
>   
>> memory.limit()
>>     
> [1] 1535.875
>   
>> memory.size()
>>     
> [1] 29.42623
>   
>> memory.profile()
>>     
>        NULL      symbol    pairlist     closure environment     promise
>           1        9368      407965       12045        2013        7091
>    language     special     builtin        char     logical     integer
>      107052         269        2397       11503       13032        8429
>      double     complex   character         ...         any        list
>       11122          17      122950           1           0        7535
>  expression    bytecode externalptr     weakref         raw
>           1           0        1341         359           1
>   
>> gc()
>>     
>          used (Mb) gc trigger (Mb) max used (Mb)
> Ncells 727690 19.5    1166886 31.2   984024 26.3
> Vcells 282062  2.2     786432  6.0   519695  4.0
>
> ############# Memory values after I run the syntax###############
>
>   
>> memory.limit()
>>     
> [1] 4000
>   
>> memory.size()
>>     
> [1] 1417.948
>   
>> memory.profile()
>>     
>        NULL      symbol    pairlist     closure environment     promise
>           1        9921      466736       12211        2013        7091
>    language     special     builtin        char     logical     integer
>      114491         269        2397       14534       13341       46991
>      double     complex   character         ...         any        list
>       35508          17      131349           1           0       14663
>  expression    bytecode externalptr     weakref         raw
>           1           0        1324         342           1
>   
>> gc()
>>     
>           used (Mb) gc trigger  (Mb)  max used   (Mb)
> Ncells  876371 23.5    1835812  49.1   1835812   49.1
> Vcells 1247398  9.6  121622414 928.0 180932899 1380.5
>   
>> memory.size(TRUE)
>>     
> [1] 1541.688
>
>
> ############# gc() values during the process###############
>
>
> Garbage collection 330 = 271+30+29 (level 2) ...
> 23.6 Mbytes of cons cells used (48%)
> 9.9 Mbytes of vectors used (8%)
> Garbage collection 331 = 271+30+30 (level 2) ...
> 23.6 Mbytes of cons cells used (48%)
> 117.8 Mbytes of vectors used (49%)
> Garbage collection 332 = 271+30+31 (level 2) ...
> 23.6 Mbytes of cons cells used (48%)
> 225.8 Mbytes of vectors used (64%)
> Garbage collection 333 = 271+30+32 (level 2) ...
> 23.6 Mbytes of cons cells used (48%)
> 333.8 Mbytes of vectors used (72%)
> Garbage collection 334 = 272+30+32 (level 0) ...
> 23.6 Mbytes of cons cells used (48%)
> 441.9 Mbytes of vectors used (95%) 

... deletions
> Garbage collection 454 = 369+38+47 (level 2) ...
> 24.2 Mbytes of cons cells used (49%)
> 1217.2 Mbytes of vectors used (91%)
> Garbage collection 455 = 369+38+48 (level 2) ...
> 24.2 Mbytes of cons cells used (49%)
> 1325.1 Mbytes of vectors used (91%)
> Garbage collection 456 = 369+38+49 (level 2) ...
> 24.4 Mbytes of cons cells used (50%)
> 1380.4 Mbytes of vectors used (82%)
> Garbage collection 457 = 370+38+49 (level 0) ...
> 24.4 Mbytes of cons cells used (50%)
> 1380.4 Mbytes of vectors used (82%)
> Error: cannot allocate vector of size 216.0 Mb
>   

It looks as though your memory use really is growing over the run, up to 
1.4 GB.  At this point the memory manager was unable to find a 216 MB 
block. 

This looks like a problem in your code, or in the package:  you seem to 
have a memory leak.  You can't increase memory indefinitely, eventually 
you'll run out.

Duncan Murdoch




More information about the R-help mailing list