diff --git a/app/example_plugin/pythonhandler.cpp b/app/example_plugin/pythonhandler.cpp index 1608b2a..19d1016 100644 --- a/app/example_plugin/pythonhandler.cpp +++ b/app/example_plugin/pythonhandler.cpp @@ -199,7 +199,10 @@ QVariant PythonHandler::pythonObjectToQVariant(PyObject *obj) map[key] = pythonObjectToQVariant(pValue); } } + +#ifdef _RELEASE Py_DECREF(pKeys); +#endif return map; } else if (obj == Py_None) { @@ -222,14 +225,17 @@ QString PythonHandler::capturePythonError() { PyObject* pstr = PyObject_Str(pvalue); if (pstr) { errorMsg = QString::fromUtf8(PyUnicode_AsUTF8(pstr)); +#ifdef _RELEASE Py_DECREF(pstr); +#endif } } - +#ifdef _RELEASE // 清理 Py_XDECREF(ptype); Py_XDECREF(pvalue); Py_XDECREF(ptraceback); +#endif return errorMsg; } @@ -284,8 +290,11 @@ QVariant PythonHandler::executeScript(const QString &scriptPath, PyErr_Print(); } emit addLog("无法找到函数:" + functionName); + +#ifdef _RELEASE Py_XDECREF(pFunc); Py_DECREF(pModule); +#endif return QVariant(); } @@ -427,7 +436,10 @@ QVariant PythonHandler::executeCode(const QString &code) if (pResult) { QVariant result = pythonObjectToQVariant(pResult); + +#ifdef _RELEASE Py_DECREF(pResult); +#endif return result; } else { PyErr_Print();