import collections import gc import weakref def create_reference(): class A(object): pass class B(A): parents = collections.OrderedDict([ (A, A.__name__), ]) return weakref.ref(A) reference = create_reference() gc.collect() assert reference() is None