Resolve circular reference

moerchendiser2k3 googler.1.webmaster at spamgourmet.com
Thu Jan 6 21:24:13 EST 2011


Hi,

I have a small problem with circular references. I embedded Python
into my app and I have two types which are flagged with
Py_TPFLAGS_BASETYPE so I can inherit Python types from these types.
Lets call my C types A and B.


Here is the dependency:

class Foo(A):
    e=Bar()

class Bar(B):
    def __init__(self, p):
        self.p=p
i=Foo()
j=Bar(i)

Everything works fine, the problem starts when I start to make a
circular reference in Python. In my embedded app I have a reference to
instance A. When I decref this reference its still alive because the
instance j(Bar) makes this object still alive. Is there any chance to
force this? Because without A the instance A shouldnt be alive
anymore. Thanks for any hint!!

Bye



More information about the Python-list mailing list