如何清除通过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
Run Code Online (Sandbox Code Playgroud)
不幸的影响是,在我的应用程序中,内存使用量增加,直到没有足够的然后它崩溃...来自rpy2 文档:
对象本身仍然可用,并且在从Python中删除foo之前保护其免受R的垃圾收集
但即使这样做:
import rpy2.robjects as r
a = r.r('a = matrix(NA, 2000000, 50)')
r.r.rm('a')
del a
r.r.gc()
Run Code Online (Sandbox Code Playgroud)
没有释放使用的内存......
编辑:rpy2 2.0,Win XP,R 2.12.0