Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05e01ee

Browse files
committed
Add a testcase to ensure that cycles going through the __class__ link
of a new-style instance are detected by the garbage collector.
1 parent c5fe5eb commit 05e01ee

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Lib/test/test_gc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class C(B, A):
8383
gc.collect()
8484
del a
8585
expect_nonzero(gc.collect(), "newinstance(2)")
86+
del B, C
87+
expect_nonzero(gc.collect(), "newinstance(3)")
88+
A.a = A()
89+
del A
90+
expect_nonzero(gc.collect(), "newinstance(4)")
91+
expect(gc.collect(), 0, "newinstance(5)")
8692

8793
def test_method():
8894
# Tricky: self.__init__ is a bound method, it references the instance.

0 commit comments

Comments
 (0)