Skip to content
Prev 166884 / 398502 Next

Memory Size & Allocation in R

Hi Brigid,

You will probably get some more informed answers in a bit, but to give 
you some quick things to try...

There's no size limit to an object like you are referring to. When 
you're having problems with small objects or simple operations, it 
sounds like you've used up the memory for running R. Try running gc() to 
get memory usage information -- what you're looking at may be static (I 
forget) giving the upper limits, rather than what you are actually using.

You may have an object that is too large or the accumulation of objects 
is too large. You can do object.size() to find it, or to look at all of 
your objects in your environment (sorted by size):

sort( sapply(ls(),function(x){object.size(get(x))}))

If you remove a large object (using rm()), call gc() again to flush out 
the memory (and see your improvement).

On the other hand, manipulating *very* large objects requires a lot of 
memory, as does some expensive operations of course, so if you are 
running into problems only when you are handling that object or running 
a certain program, it may be that you don't have enough memory on your 
computer for that task.

I also find that there are memory leaks when I use R in Windows for a 
long time. If I shut down R and start up again, especially after very 
memory intensive tasks, I often have a good bit more memory when I start 
back up.

Best,
Elizabeth
Brigid Mooney wrote: