O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reference Counting

Unlike programs written in Python, C extensions occasionally have to manipulate the reference count of Python objects. This is done using the following macros:

MacroDescription
Py_INCREF(obj)Increments the reference count of obj, which must be non-null
Py_DECREF(obj)Decrements the reference count of obj, which must be non-null
Py_XINCREF(obj)Increments the reference count of obj, which may be null
Py_XDECREF(obj)Decrements the reference count of obj, which may be null

Manipulating the reference count of Python objects in C is a delicate topic, and readers are strongly advised to consult the “Extending and Embedding the Python Interpreter” document available at http://www.python.org/doc/ext before proceeding any further. With this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required