Resolve circular reference

MRAB python at mrabarnett.plus.com
Thu Jan 6 21:59:26 EST 2011


On 07/01/2011 02:24, moerchendiser2k3 wrote:
> 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!!
>
Force what?

j refers to i, i refers to Foo, Foo refers to A. Therefore A should be
alive.



More information about the Python-list mailing list