How to DECREF an Python object to return?

Fredrik Lundh fredrik at effbot.org
Fri Jan 5 11:02:53 EST 2001


Jae-wook Ahn wrote:
> 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?

in this case, you can simply return the tuple:

    return tuple;

:::

In the general case, you can store the return value
in a temporary variable:

    PyObject* result;

    ...

    result = PyBuildValue("OO", tuple, othertuple);

    Py_DECREF(tuple);
    Py_DECREF(othertuple);

    return result;

Hope this helps!

</F>





More information about the Python-list mailing list