def test_cyclic_gc(): from pybind11_tests import DynamicClass # One object references itself instance = DynamicClass() instance.circular_reference = instance cstats = ConstructorStats.get(DynamicClass) if cstats.alive() != 1: raise AssertionError del instance if cstats.alive() != 0: raise AssertionError # Two object reference each other i1 = DynamicClass() i2 = DynamicClass() i1.cycle = i2 i2.cycle = i1 if cstats.alive() != 2: raise AssertionError del i1, i2 if cstats.alive() != 0: raise AssertionError
def test_cyclic_gc(): from pybind11_tests import DynamicClass # One object references itself instance = DynamicClass() instance.circular_reference = instance cstats = ConstructorStats.get(DynamicClass) assert cstats.alive() == 1 del instance assert cstats.alive() == 0 # Two object reference each other i1 = DynamicClass() i2 = DynamicClass() i1.cycle = i2 i2.cycle = i1 assert cstats.alive() == 2 del i1, i2 assert cstats.alive() == 0