How to DECREF an Python object to return?
Ahn, Jae-wook
mail at codex.pe.kr
Fri Jan 5 10:49:04 EST 2001
Hi.
I wrote a C extension module that recieves a string and extracts some nouns
(in Korean) from the string and return them. The group of nouns to return is
a tuple, and the number of elements varies depending on the source string.
So I created a tuple object and returned it using Py_BuildValue. The module
returned the value I wanted, but because I created a Python object for the
tuple, I have to free (Py_DECREF) the memory it occupies.
My question is in what point I can free it? The function works like this.
1. recieves a sentence.
2. extracts nouns from it
3. create a tuple object
4. set the elements for the tuple
5. return the tuple object ( return PyBuildValue("O", tuple) )
Because I want the tuple get returned, I can't free it before returning it,
but after I return it, the function I created finishes. How can I get the
tuple back and free the memory?
More information about the Python-list
mailing list