Chris Bainbridge wrote: > 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).
Pyrex seems to have weakref support: http://www.sagemath.org:9002/sage_trac/ticket/165 Here's a simple patch that seems to run Martin Vopatek's test case without running out of memory. I have no idea if it does anything else, though! Please test carefully. Ethan
Index: src/geomobject.pyx
===================================================================
RCS file: /cvsroot/pyode/pyode/src/geomobject.pyx,v
retrieving revision 1.4
diff -u -r1.4 geomobject.pyx
--- src/geomobject.pyx 17 Jan 2006 09:07:54 -0000 1.4
+++ src/geomobject.pyx 29 May 2007 23:10:51 -0000
@@ -52,6 +52,8 @@
# A dictionary with user defined attributes
cdef object attribs
+ cdef object __weakref__
+
def __new__(self, *a, **kw):
self.gid = NULL
self.space = None
Index: src/ode.pyx
===================================================================
RCS file: /cvsroot/pyode/pyode/src/ode.pyx,v
retrieving revision 1.17
diff -u -r1.17 ode.pyx
--- src/ode.pyx 10 Nov 2006 10:53:40 -0000 1.17
+++ src/ode.pyx 29 May 2007 23:10:52 -0000
@@ -151,7 +151,8 @@
######################################################################
# Lookup table for geom objects: C ptr -> Python object
-_geom_c2py_lut = {}
+import weakref
+_geom_c2py_lut = weakref.WeakValueDictionary()
# Mass
include "mass.pyx"
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Pyode-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyode-user
