'Is it necessary to release some resources allocated by the Python C API
I have the following C code that calls the Python API library:
PyObject *obj;
PyObject *arguments;
arguments = PyTuple_New(2);
PyTuple_SetItem(arguments, 0, PyLong_FromLongLong(10));
PyTuple_SetItem(arguments, 1, PyLong_FromLongLong(20));
obj = PyObject_CallObject(my_function, arguments); // should "obj" be released after being used?
PyLong_AsLongLong(obj);
Py_DECREF(arguments); // is this instruction necessary?
I have two questions (both are in the code as comments), namely: 1) should the variable obj be released after being used (if yes, how is this done?) and 2) do we need to decrease the reference counter of variable arguments (i.e. do we need Py_DECREF(arguments);)? Thanks for all the help in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
