[C++-sig] Cycles won't be deleted

bob at glumol.com bob at glumol.com
Mon Dec 19 23:01:04 CET 2005


Hello,

I'm sorry if this question has already been asked but I didn't find an
answer on the archives.
With the Python code :

class C: pass

c1 = C()
c2 = C()
c1.child = c2
c2.parent = c1
del c1
del c2
import gc
gc.collect()

gc.collect() will return 2.
Now if C is not a pure Python class but a BPL one, gc.collect() will
return 0 and the 2 objects seem to never be deleted.
I can define 'child' and 'parent' as members of the C++ class (using a
shared_ptr and a weak_ptr, that works) but if an other cycle is defined in
Python, the objects won't be deleted.

Could someone explain me why such a behavior ?
(I'm using Windows, Boost 1.33.1 and Visual Studio Express 2005)

Thanks by advance
Sylvain B.






More information about the Cplusplus-sig mailing list