Py_INCREF Py_DECREF and Reference Counting

Hi everyone

Based on your experience, do you think writing a CPython function in 2 steps to avoid overthinking about the reference counting will help. For example:

  • step 1: Write the function to get the job done without thinking about the Py_INCREF AND Py_DECREF and their friends.
  • step 2: Review and modify the function to fill the gaps for reference counting.

What do you think? And if you have your own way to deal with the reference counting while you writing your code, I hope to share it with us.

Thank your :pray:

Step 1 pick a library that deals with the ref counting problems for you.

Especially if you are writting in C++ or rust there are libraries that take care of the ref counting for you. Iā€™m the author of PyCXX and there are are other libraries you could use.

3 Likes