tp_is_gc
is a function pointer field in PyTypeObject
.
Its purpose is to allow some objects in a class to be GC’d while others are not. This was needed for classes before we added immortal objects, as some were statically allocated and not GC’d, whereas others were heap allocated and needed to be handled by the cycle collector.
However, we now have immortal objects (and have since 3.12), so there is no need for this hook. Statically allocated objects should be immortal, and thus not touched by the GC.
Having this extra function adds overhead to the GC and complicates implementation of C extensions. We should deprecate tp_is_gc
and aim to remove it when appropriate. Probably in 3.19 or thereabouts.