# Pastebin kNVd2dlY import gc import weakref class A: pass def main(a): lst = [] a = weakref.ref(a, lambda _: lst.append(True)) while not lst: gc.collect() main(A())