[R] memory allocation in R

Simon Urbanek simon.urbanek at r-project.org
Mon Nov 28 03:31:32 CET 2011


On Nov 23, 2011, at 10:42 AM, Marc Jekel wrote:

> Dear R community,
> 
> I was observing a memory issue in R (latest 64bit R version running on a win 7 64 bit system) that made me curious.
> 
> I kept track of the memory f my PC allocated to R to calculate + keep several objects in the workspace. If I then save the workspace, close R, and open the workspace again, less memory is allocated to keep the same set of variables into the workspace. For my case, the reduction in memory size was quite significant (approx. 2 GB).
> 
> Does anyone know why R behaves in this manner - put differently: What does R keep in the workspace beyond the objects before I close R? Can I induce the reduction in memory without the need to close R?
> 

You can explicitly clean up using gc() [do not use gctorture() - that is nonsensical this context]. After that R keeps in memory only objects that are currently in use. What is in the workspace (global environment) is explicitly under your control. Note, however, that the system (reported by tools like ps or top) may not be able to reclaim memory (in particular Linux) even though R has released it - see R FAQ 7.42 for details.

Cheers,
Simon


> Thanks for an email!
> 
> Marc
> 
> ______________________________________________
> 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.
> 
> 



More information about the R-help mailing list