MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_cyclic_gc

Function test_cyclic_gc

tests/test_methods_and_attributes.py:363–383  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

361 reason="3.14.0b1/2 managed dict bug: https://github.com/python/cpython/issues/133912",
362)
363def test_cyclic_gc():
364 # One object references itself
365 instance = m.DynamicClass()
366 instance.circular_reference = instance
367
368 cstats = ConstructorStats.get(m.DynamicClass)
369 assert cstats.alive() == 1
370 del instance
371 pytest.gc_collect()
372 assert cstats.alive() == 0
373
374 # Two object reference each other
375 i1 = m.DynamicClass()
376 i2 = m.DynamicClass()
377 i1.cycle = i2
378 i2.cycle = i1
379
380 assert cstats.alive() == 2
381 del i1, i2
382 pytest.gc_collect()
383 assert cstats.alive() == 0
384
385
386@pytest.mark.xfail("env.PYPY", strict=False)

Callers

nothing calls this directly

Calls 3

DynamicClassMethod · 0.80
aliveMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected