From: Matthias B. <ba...@ir...> - 2005-08-04 13:28:48
|
Chris Bainbridge wrote: > Hi, the following code appears to leak Body and dict objects. Memprof > [...] > I've looked at the pyode code. It appears that nothing is ever removed > from the global dictionary _geom_c2py_lut. Should this be done in geom > __dealloc__ ? The _geom_c2py_lut is a dictionary that serves as a lookup table to convert the geom pointer received from ODE into the appropriate Python geom object (which has to be done during collisions). So when a geom is created it adds itself to the dictionary and indeed, it is never removed from there. The geom cannot remove itself in __dealloc__() because as long as there's a reference in the dictionary it is not destroyed and __dealloc__() is never called. The solution would be weak references but at the time I wrote the stuff Pyrex didn't support this. I contacted the author, but I believe the current version of Pyrex still doesn't support it (I haven't checked explicitly but at least I never noticed anything in the changelogs). As you said in your other mail, the workaround is to clear the dictionary manually when you're creating a new simulation scene. > Similarly should geomobject __dealloc__ do 'del self.body'? Doesn't Python do that itself? Hm, but on the other hand, it's declared using "cdef", so you'r probably right and we should manually delete it in __dealloc__... Then it would be the same for self.space in the Geoms and for self.world in the Body and the Joints. - Matthias - |