Reference Counting Mismatches: Top Cause of Leaks and Crashes

Forgetting to call Py_DECREF on a new reference leads to memory leaks, as the Python object's reference count never drops to zero, preventing deallocation. Conversely, calling Py_DECREF too early or too often can result in use-after-free errors or interpreter crashes.

Sources

Open the full topic