Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
BUG: Fix _ctypes class circular reference. (#13808) #14851
Backport of #14469.
In _ctypes class, ctypes.cast() was called twice. It causes circular reference
from sys import getrefcount import ctypes z = ctypes.c_int(1) pc = ctypes.cast(ctypes.byref(z), ctypes.c_char_p) print(getrefcount(pc)) # 2: from getrefcount() pv = ctypes.cast(pc, ctypes.c_void_p) print(getrefcount(pc)) # 3: from getrefcount(), pc._objects; circular ref: pc -> pc._objects -> pc! _objects = pc._objects print(_objects == pv._objects) print(getrefcount(_objects)) # 4: from getrefcount(), _objects, pc._objects, pv._objects pc = pv = None print(getrefcount(_objects)) # 3: from getrefcount(), _objects; circular ref: _objects -> pc -> pc._objects!