引用计数

The functions and macros in this section are used for managing reference counts of Python objects.

Py_ssize_t Py_REFCNT ( PyObject * o )

Get the reference count of the Python object o .

Note that the returned value may not actually reflect how many references to the object are actually held. For example, some objects are immortal and have a very high refcount that does not reflect the actual number of references. Consequently, do not rely on the returned value to be accurate, other than a value of 0 or 1.

使用 Py_SET_REFCNT() function to set an object reference count.

3.10 版改变: Py_REFCNT() is changed to the inline static function.

3.11 版改变: The parameter type is no longer const PyObject * .