CPython's Internal Flags for GC Tracking

CPython identifies objects suitable for cyclic garbage collection using the `Py_TPFLAGS_HAVE_GC` flag within their `PyTypeObject` structure. This flag mandates the implementation of `tp_traverse` and `tp_clear` handlers, and requires objects to be explicitly registered and unregistered with the collector using `PyObject_GC_Track()` and `PyObject_GC_UnTrack()`.

Sources

Open the full topic