There are many posts concerning a memory leak in rpy2, and I have to say that it's also affecting me. But fortunately, after losing a couple of days on this problem, I found this webpage that kind of solve my problem:
http://code.activestate.com/recipes/511474/ The solution is to wrap the work done by rpy2 in a function, and to run it in a seperate process. When this process finish, you can be sure that all ressources used by rpy2 are released! I know that it is a hack, but at least it worked for me! I hope this could help some of you who have the same problem. Réjean > Thanks, > I'll look into that ASAP. > > > > L. > > > > On Thu, 2009-04-23 at 12:29 +1000, Denham Robert wrote: > >> I know this was raised before, and I saw a suggestion that using >> gc.collect seemed to fix things, but I am getting I think a memory leak >> in rpy2 which doesn't seem to occur in rpy. This could be how I am >> coding things of course. Here is an example: >> >> import rpy2.robjects as robjects >> from numpy import * >> import rpy2.robjects.numpy2ri >> import gc >> >> robjects.r('set.seed(99813)') >> aa = array(robjects.r.runif(205)) >> bb = arange(0,1,step=1/205.0)robjects.r('library(locfit)') >> lfraw = robjects.globalEnv.get("locfit.raw") >> >> ##and try this many times: >> for i in range(90000): >> if i%1000==0: >> gc.collect() >> print i >> res = lfraw(bb,aa) >> >> >> If I monitor this using top, the memory use steadily increases. This >> does not happen with the equivalent code in rpy. We would like to use >> some R functions many times, so the memory leak is of concern. Does >> anyone have any insight to this problem -- perhaps I can modify my code >> to avoid it, or should we go back to rpy? >> >> I am using rpy2 2.0.3 on linux on 64bit suse running R-2.8.0 >> >> >> >> >> Thanks >> Robert ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list