App/Gui: fix memory leaks:
+ add function to cleanup units and quantities in debug build + fix reference leak in PropertyVector::getPyPathValue() + fix reference leak in PropertyPlacement::getPyPathValue() + in InterpreterSingleton::init() use a static std::vector<wchar_t*> instead of a C array to free memory at program end + in MainWindow::closeEvent() explicitly delete all task watchers + in ReportOutputObserver constructor pass parent to QObject + in PropertyEditor destructor explicitly delete QItemEditorFactory
This commit is contained in:
@@ -340,7 +340,6 @@ Application::Application(std::map<std::string,std::string> &mConfig)
|
||||
|
||||
// Translate module
|
||||
PyObject* pTranslateModule = (new Base::Translate)->module().ptr();
|
||||
Py_INCREF(pTranslateModule);
|
||||
PyModule_AddObject(pAppModule, "Qt", pTranslateModule);
|
||||
|
||||
//insert Units module
|
||||
@@ -1499,6 +1498,23 @@ int Application::_argc;
|
||||
char ** Application::_argv;
|
||||
|
||||
|
||||
void Application::cleanupUnits()
|
||||
{
|
||||
try {
|
||||
Base::PyGILStateLocker lock;
|
||||
Py::Module mod (Py::Module("FreeCAD").getAttr("Units").ptr());
|
||||
|
||||
Py::List attr(mod.dir());
|
||||
for (Py::List::iterator it = attr.begin(); it != attr.end(); ++it) {
|
||||
mod.delAttr(Py::String(*it));
|
||||
}
|
||||
}
|
||||
catch (Py::Exception& e) {
|
||||
Base::PyGILStateLocker lock;
|
||||
e.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::destruct(void)
|
||||
{
|
||||
// saving system parameter
|
||||
@@ -1529,6 +1545,11 @@ void Application::destruct(void)
|
||||
_pcSysParamMngr = 0;
|
||||
_pcUserParamMngr = 0;
|
||||
|
||||
#ifdef FC_DEBUG
|
||||
// Do this only in debug mode for memory leak checkers
|
||||
cleanupUnits();
|
||||
#endif
|
||||
|
||||
// not initialized or double destruct!
|
||||
assert(_pcSingleton);
|
||||
delete _pcSingleton;
|
||||
|
||||
Reference in New Issue
Block a user