[R] Memory warning (Reached total allocation of ...) - but no error

Magnus Torfason zulutime.net at gmail.com
Wed May 5 18:19:35 CEST 2010


Hi all,

I'm getting the following warnings inside a loop:

Warning messages:
1: In calc.measures(g, 1, i) :
   Reached total allocation of 1535Mb: see help(memory.size)
2: In calc.measures(g, 1, i) :
   Reached total allocation of 1535Mb: see help(memory.size)

Usually, when I see these warnings, they are accompanied with an error 
message (Error: cannot allocate ...), but not in this case. I'm 
wondering how to react. I've tried adding a call to gc() inside the 
loop, i.e.:

for (i in 1:1000)
{
     calc.measures(g, 1, i)
     gc()
}

This gets rid of the warnings, but increases the running time by a 
factor of ten or so. So I'm thinking that maybe the warnings are simply 
telling me that calc.measures allocated so many temporary variables that 
garbage collection had to be triggered. But then I get a nagging feeling 
- why is R warning me that GC had to be triggered - isn't that the whole 
point of GC, that it gets triggered when memory is running out?

I'd be grateful for advise on this: Should I just ignore these warnings 
as long as there are no errors, should I bite the bullet and call gc() 
manually, or is there a third way to deal with this?

Best,
Magnus

ps. The reason the code is now in a loop is because a vectorized version 
gave me the same errors. So vectorization does not seem to be a usable 
fix here.



More information about the R-help mailing list