From: Chris B. <chr...@gm...> - 2007-05-28 16:06:34
|
On 28/05/07, Martin Vopatek <vo...@na...> wrote: > Hello > > There seem to be a memory leak in PyODE due to > undeleted geom objects. I found the problem while working on a > simulator that need to create and delete many geom objects. > I used the Heapy memory profiler (part of Guppy-PE) to determine > the cause of the leak. > I'm running python-2.4.2 and PyODE 1.2.0. Attached a reply from a thread in 2005 (since I can't find it archived anywhere). Matthias Baas <ba...@ir...> to pyode-user 04/08/05 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). |