Inheriting from 'object' introduces cycled reference.

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Jan 16 03:56:10 EST 2002


"Jason Orendorff" <jason at jorendorff.com> writes:

> Kerim Borchaev wrote:
> > Subject: Inheriting from 'object' introduces cycled reference.
> > Is it intended behavior?
> 
> Yes.  The cycle is caused by a weak back-reference from 'object'
> to the subclass.  That weak reference is used to implement
> the new __subclasses__() method that types now have.

Well, no (I think). I haven't analysed this closely, but I think you
are right that this is caused by the __weakref__ member of Test.
However, that is *not* there to deal with back-references from object.
Instead, it serves to allow weak references to new-style classes, e.g.

t=Test()
import weakref
w=weakref.ref(t)

> Note that the cycle doesn't prevent types from being GC'd nicely.

That is certainly the case.

Regards,
Martin



More information about the Python-list mailing list