According to the accepted answer in Py_INCREF/DECREF: When, Python objects that are created by functions but not explicitly returned should have their reference counts decremented via DECREF
. Does this guideline apply to temporary variables? For example, I could use this:
void PythonInterface::SetModule (const char *filename)
{
PyObject *name = PyUnicode_DecodeFSDefault (filename);
_module = PyImport_Import (name);
Py_XDECREF (name);
}
or this:
void PythonInterface::SetModule (const char *filename)
{
_module = PyImport_Import (PyUnicode_DecodeFSDefault (filename));
}
Are these two bits of code identical, or will the second example cause problems?