[R] Memory not release when an environment is created

Olivier Merle oliviermerle35 at gmail.com
Thu Sep 22 17:41:20 CEST 2016


Dear,

When I use big data for a temporary use it seems that the memory is not
released when a function/environement is created nearby.
Here the reproducible exemple:

test<-function(){
x=matrix(0,50000,10000)
y=function(nb) nb^2
return(y)
}
xx=test() # 3 Go of Ram is used
gc() # Memory is not released !! even if x has been destroyed [look into
software mem used]
format(object.size(xx),units="auto") # 1.4 KiB => R is worng on the size of
the object
rm(xx)
gc() # Memory is released

## Classic
test2<-function(){
x=matrix(0,50000,10000)
y=1
return(y)
}
xx=test2() # Memory is used
gc() # => Memory is released

How can I release the data in test without destroying the xx object ? As x
which is big object is destroyed, I though I could get my memory back but
it seems that the function y is keeping the x object.

Best

	[[alternative HTML version deleted]]



More information about the R-help mailing list