When rebuilding rpy2 after commenting out line 106 in setup.py:
define_macros.append(('RPY_DEBUG_PRESERVE', 1))

I can see that it seems that R objects are
preserved but not released until the termination of the python process.
In fact during each iteration I have 6 R objects preserved, but only 4 
released - the release of the two last ones is deferred to the 
termination of the python process. The question now is "why".


Laurent


laurent oget wrote:
> I have been able to improve the leak considerably with your suggestion
> and also attaching the dataFrame instead of passing it as an argument
> of lm every time. As an added benefit this reduces the number of copy,
> which increases performance. It is still leaking, though....
> 
> Laurent
> 
> 2008/11/21 Laurent Gautier <[EMAIL PROTECTED]>:
>> laurent oget wrote:
>>> is there something i can do to prevent the following script from leaking
>>> memory?
>>
>> There seems to be something happening.
>> (more below)
>>
>>> Laurent
>>>
>>> from rpy2.robjects import r,RVector,RDataFrame
>>> from rpy2.rlike.container import TaggedList
>>> from math import sin
>>> import array
>>>
>>> size=100
>>> xx=[]
>>> for x in range(size):
>>>    xx.append(RVector(array.array('f',[sin(0.1*(y+x))for y in
>>> range(1000)])))
>>>
>>
>> (side note: the line above could write easier
>>
>> from rpy2.robjects import FloatVector
>>
>> for x in range(size):
>>    xx.append(FloatVector([sin(0.1 * (x+y) for y in range(1000)]))
>> )
>>
>>
>>> formula='x%s~%s'%(0,'+'.join(['x%d'%(i+1) for i in range(size-1)]))
>>>
>>> t=['x%d'%i for i in range(size)]
>>> df=RDataFrame(TaggedList(xx,tags=t))
>>>
>>> done=False
>>> i=0
>>> while not done:
>>>    print i
>>>    i=i+1
>>>    model=r.lm(formula,df)
>> I thought that the following would solve the problem... but it does not.
>> The increase in running speed suggests that this is because there is less
>> copying (therefore the problem about copying and protecting R objects and
>> never unprotecting them). The growth of the process is slower, but still
>> there...
>>
>>
>> from rpy2.robjects import globalEnv
>>
>> globalEnv["dataf"] = df
>>
>> done=False
>> i=0
>> while not done:
>>    print i
>>    i=i+1
>>    model=r('lm("%s", data=dataf)' %formula)
>>
>>
>> The problem will likely require a closer look.
>>
>>
>>> -------------------------------------------------------------------------
>>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>>> challenge
>>> Build the coolest Linux based applications with Moblin SDK & win great
>>> prizes
>>> Grand prize is a trip for two to an Open Source event anywhere in the
>>> world
>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>> _______________________________________________
>>> rpy-list mailing list
>>> rpy-list@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>>


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to