清除rpy2使用的内存
如何清除通过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
不幸的结果是,在我的应用程序中,内存使用量增加,直到没有足够的然后它崩溃...来自rpy2文档:
对象本身仍然可用,
并保护免受R的垃圾
收集直到foo被删除
蟒蛇
但即使这样做:
import rpy2.robjects as r
a = r.r('a = matrix(NA, 2000000, 50)')
r.r.rm('a')
del a
r.r.gc()
没有释放使用的内存......
编辑:rpy2 2.0,Win XP,R 2.12.0
没有找到相关结果
已邀请:
1 个回复
疾桓
来强制rpy2释放该大矩阵,并且在删除它并运行R的内部
函数之后再次执行。在睡眠循环中运行它 - 使用
来观察内存使用量的增加/减少。 在Ubuntu 10.0.4上使用Python 2.6运行,python-rpy版本2.0.8链接到R版本2.10.1。希望这有助于您取得一些进展: