From 1b0d6e3c26c5dc54c6eae3cb21dc36a22ab1274c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 16 Feb 2018 14:52:05 +0100 Subject: [PATCH] Avoid some memory leaks at shutdown StatusBarManager needs to delete its contexts when dropping them, QActions should be parented, and in ProjectWindow we can save an allocation. Change-Id: Idee075d4f2ce8014f22f73453987d1ab6539cf18 Reviewed-by: Tobias Hunger Reviewed-by: Eike Ziller --- src/plugins/coreplugin/statusbarmanager.cpp | 4 +++- src/plugins/coreplugin/windowsupport.cpp | 2 +- src/plugins/projectexplorer/projectwindow.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/coreplugin/statusbarmanager.cpp b/src/plugins/coreplugin/statusbarmanager.cpp index 193584fa124..c653928ad83 100644 --- a/src/plugins/coreplugin/statusbarmanager.cpp +++ b/src/plugins/coreplugin/statusbarmanager.cpp @@ -95,8 +95,10 @@ static void createStatusBarManager() QObject::connect(ICore::instance(), &ICore::coreAboutToClose, [] { // This is the catch-all on rampdown. Individual items may // have been removed earlier by destroyStatusBarWidget(). - for (const QPointer &context : m_contexts) + for (const QPointer &context : m_contexts) { ICore::removeContextObject(context); + delete context; + } m_contexts.clear(); }); } diff --git a/src/plugins/coreplugin/windowsupport.cpp b/src/plugins/coreplugin/windowsupport.cpp index 87c5985ba03..88a305560c4 100644 --- a/src/plugins/coreplugin/windowsupport.cpp +++ b/src/plugins/coreplugin/windowsupport.cpp @@ -162,7 +162,7 @@ void WindowList::addWindow(QWidget *window) m_windows.append(window); Id id = Id("QtCreator.Window.").withSuffix(m_windows.size()); m_windowActionIds.append(id); - auto action = new QAction(window->windowTitle(), 0); + auto action = new QAction(window->windowTitle(), ActionManager::instance()); m_windowActions.append(action); QObject::connect(action, &QAction::triggered, [action]() { WindowList::activateWindow(action); }); action->setCheckable(true); diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index 064e1cfffc3..f1293d5b7a8 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -369,7 +369,7 @@ public: m_selectorTree = new SelectorTree; m_selectorTree->setModel(&m_projectsModel); - m_selectorTree->setItemDelegate(new SelectorDelegate); + m_selectorTree->setItemDelegate(&m_selectorDelegate); m_selectorTree->setContextMenuPolicy(Qt::CustomContextMenu); connect(m_selectorTree, &QAbstractItemView::activated, this, &ProjectWindowPrivate::itemActivated); @@ -595,6 +595,7 @@ public: ProjectWindow *q; ProjectsModel m_projectsModel; ComboBoxModel m_comboBoxModel; + SelectorDelegate m_selectorDelegate; QComboBox *m_projectSelection; SelectorTree *m_selectorTree; QPushButton *m_importBuild;