How to free /destroy object created by PyTuple_New

grbgooglefan ganeshborse at
Sun Apr 5 08:20:34 CEST 2009

On Apr 4, 10:27 pm, Andrew Svetlov <andrew.svet... at> wrote:
> To destroy every python object you need to call Py_DECREF.
> To call python code fron you C thread you need to use pair
> PyGILState_Ensure/PyGILState_Release.

In my case, my C application has multiple threads & they are accessing
a single Python Interpreter which was initialized by 1st main thread.
In that case also, do I need to use PyGILState_Ensure/
PyGILState_Release APIs?

I am not using Python interpreter level threads.

Can I have a Python interpreter per thread so that I won't have issues
of some data inside Python interpreters being gettint accidently
overwritten/ freed by other thread?

Will Py_DECREF release the items set in that tuple using call to
PyTuple_SetItem? Or do I need to separately call Py_DECREF for them
What is correct sequence for calling Py_DECREF & Py_INCREF?
If I dont call Py_DECREF, will that object (PyTuple) not get freeed at
all, causing memory leak?

Please guide.

More information about the Python-list mailing list