Top shows that R
is using 3.5GB of memory.
After executing the following code:
rm(list=ls(all=TRUE))
the 3.5GB of resources were still in used by R
.
How can we effectively empty all resources occupied by R
?
Top shows that R
is using 3.5GB of memory.
After executing the following code:
rm(list=ls(all=TRUE))
the 3.5GB of resources were still in used by R
.
How can we effectively empty all resources occupied by R
?
As Mikael Jagan said in a comment, calling gc()
will immediately run the garbage collector and return memory from unreferenced objects to the operating system. However, you generally don’t have to do this, as memory will still be freed up when actually needed by R or other processes. In the meantime, that memory may still show as in use by R, because, as Hadley explains:
Both R and the operating system are lazy: they won’t reclaim memory until it’s actually needed. R might be holding on to memory because the OS hasn’t yet asked for it back.
For more, see the section on garbage collection in Advanced R.