How can I clear objects (and the memory they occupy) created via rpy?
import rpy2.robjects as r
a = r.r('a = matrix(NA, 2000000, 50)')
del a #if I do this, there is no change in the amount of memory used
r.r('rm(list=(ls(all=TRUE)))') # Same here, the objects disappear, but the memory is still used
The unfortunate effect is that in my application, memory usage increases until there is not enough and then it crashes... From the rpy2 docs:
The object itself remains available,
and protected from R’s garbage
collection until foo is deleted from
Python
but even doing:
import rpy2.robjects as r
a = r.r('a = matrix(NA, 2000000, 50)')
r.r.rm('a')
del a
r.r.gc()
does not free the memory used...
EDIT: rpy2 2.0, Win XP, R 2.12.0
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…