![]() | We have omitted a very important topic in Python-C programming: reference counting |
![]() | Python has a garbage collection system based on reference counting |
![]() | Each object counts the no of references to itself |
![]() | When there are no more references, the object is automatically deallocated |
![]() | Nice when used from Python, but in C we must program the reference counting manually
PyObject *obj; ... Py_XINCREF(obj); /* new reference created */ ... Py_DECREF(obj); /* a reference is destroyed */ |