From 091da7e8fbc1b407d1be14ab17b8ca96a7cc5e82 Mon Sep 17 00:00:00 2001 From: Lieven Hey Date: Tue, 10 Dec 2024 13:33:12 +0100 Subject: [PATCH] feat: get rid of memory leaks from SettingsDialog SettingsDialog causes a lot of memory leaks. This patch changes the logic to only create the dialog on demand. This was asans output stays readable when no SettingsDialog is opened. --- src/mainwindow.cpp | 37 ++++++++++++++++++++----------------- src/mainwindow.h | 2 -- src/settingsdialog.cpp | 2 ++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f8918344..e11d3db7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -96,7 +96,6 @@ MainWindow::MainWindow(QWidget* parent) , m_startPage(new StartPage(this)) , m_recordPage(new RecordPage(this)) , m_resultsPage(new ResultsPage(m_parser, this)) - , m_settingsDialog(new SettingsDialog(this)) { ui->setupUi(this); @@ -111,17 +110,6 @@ MainWindow::MainWindow(QWidget* parent) auto settings = Settings::instance(); - connect(m_settingsDialog, &QDialog::accepted, this, [this, settings]() { - settings->setSysroot(m_settingsDialog->sysroot()); - settings->setAppPath(m_settingsDialog->appPath()); - settings->setExtraLibPaths(m_settingsDialog->extraLibPaths()); - settings->setDebugPaths(m_settingsDialog->debugPaths()); - settings->setKallsyms(m_settingsDialog->kallsyms()); - settings->setArch(m_settingsDialog->arch()); - settings->setObjdump(m_settingsDialog->objdump()); - settings->setPerfMapPath(m_settingsDialog->perfMapPath()); - }); - connect(settings, &Settings::sysrootChanged, m_resultsPage, &ResultsPage::setSysroot); connect(settings, &Settings::appPathChanged, m_resultsPage, &ResultsPage::setAppPath); connect(m_startPage, &StartPage::pathSettingsButtonClicked, this, &MainWindow::openSettingsDialog); @@ -419,11 +407,26 @@ void MainWindow::aboutKDAB() void MainWindow::openSettingsDialog() { - m_settingsDialog->setWindowTitle(tr("Hotspot configuration")); - m_settingsDialog->setWindowIcon(windowIcon()); - m_settingsDialog->adjustSize(); - m_settingsDialog->initSettings(); - m_settingsDialog->open(); + auto settings = Settings::instance(); + + auto settingsDialog = new SettingsDialog(this); + + connect(settingsDialog, &QDialog::accepted, this, [settingsDialog, settings]() { + settings->setSysroot(settingsDialog->sysroot()); + settings->setAppPath(settingsDialog->appPath()); + settings->setExtraLibPaths(settingsDialog->extraLibPaths()); + settings->setDebugPaths(settingsDialog->debugPaths()); + settings->setKallsyms(settingsDialog->kallsyms()); + settings->setArch(settingsDialog->arch()); + settings->setObjdump(settingsDialog->objdump()); + settings->setPerfMapPath(settingsDialog->perfMapPath()); + }); + + settingsDialog->setWindowTitle(tr("Hotspot configuration")); + settingsDialog->setWindowIcon(windowIcon()); + settingsDialog->adjustSize(); + settingsDialog->initSettings(); + settingsDialog->open(); } void MainWindow::aboutHotspot() diff --git a/src/mainwindow.h b/src/mainwindow.h index bc8f20ff..dff19949 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -27,7 +27,6 @@ class KRecentFilesAction; class StartPage; class ResultsPage; class RecordPage; -class SettingsDialog; class MainWindow : public KParts::MainWindow { @@ -78,7 +77,6 @@ public slots: StartPage* m_startPage; RecordPage* m_recordPage; ResultsPage* m_resultsPage; - SettingsDialog* m_settingsDialog; KRecentFilesAction* m_recentFilesAction = nullptr; QAction* m_reloadAction = nullptr; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 0b03cbec..8958337e 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -78,6 +78,8 @@ SettingsDialog::SettingsDialog(QWidget* parent) addCallgraphPage(); #endif addSourcePathPage(); + + setAttribute(Qt::WA_DeleteOnClose); } SettingsDialog::~SettingsDialog() = default;