Bug(ish?) report
The following function has a cache. If you are using a factory to call ctypes.POINTER in a loop, the memory usage is unbounded and unable to be reclaimed.
https://docs.python.org/3/library/ctypes.html#ctypes.POINTER
The documentation should mention that this is unbounded and should not be called in a loop, or the cache should be changed to a configurable, bounded LRU cache.
Example of a variable length type factory used by windows, and a bad func that cannot be called in a loop:
def shitemid_factory(size: int) -> Type[ctypes.Structure]:
class SHITEMID_Var(ctypes.Structure):
_fields_ = (
("cb", USHORT),
("abID", BYTE * size),
)
return SHITEMID_Var
def bad_func():
SHITEMID_Var = shitemid_factory(sz - ctypes.sizeof(USHORT))
item_var = ctypes.cast(item_ptr, ctypes.POINTER(SHITEMID_Var))
Linked PRs
Reactions are currently unavailable
Bug(ish?) report
The following function has a cache. If you are using a factory to call ctypes.POINTER in a loop, the memory usage is unbounded and unable to be reclaimed.
https://docs.python.org/3/library/ctypes.html#ctypes.POINTER
The documentation should mention that this is unbounded and should not be called in a loop, or the cache should be changed to a configurable, bounded LRU cache.
Example of a variable length type factory used by windows, and a bad func that cannot be called in a loop:
def shitemid_factory(size: int) -> Type[ctypes.Structure]: class SHITEMID_Var(ctypes.Structure): _fields_ = ( ("cb", USHORT), ("abID", BYTE * size), ) return SHITEMID_Var def bad_func(): SHITEMID_Var = shitemid_factory(sz - ctypes.sizeof(USHORT)) item_var = ctypes.cast(item_ptr, ctypes.POINTER(SHITEMID_Var))Linked PRs