Watch this stream . It would seem that what happens is that the class __mro__ attribute stores a reference to itself, creating a reference loop. You can force a full gc run, which will determine the loop and delete the object:
>>> class Foo(object): pass >>> class Bar(Foo): pass >>> import gc >>> del Bar >>> gc.collect() 3 >>> Foo.__subclasses__() []
Alternatively, if you enter other commands for a while, gc will start on its own and build a loop.
Note that you should be a little careful when testing this interactively, because the interactive interpreter stores a reference to the most recent return value in the variable "last value" _ . If you explicitly look at the list of a subclass, and then immediately try to compile, it will not work, because the variable _ will contain a list with a strong reference to the class.
source share