From 487ef6cb4ecf6577246d39fadb1445e5ff2a2368 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Mon, 14 Feb 2022 12:55:24 +0100 Subject: [PATCH] Fix minor memory leak when recreating buttons --- .../traceAnalyzer/businessObjects/traceplotlinemodel.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/traceplotlinemodel.cpp b/DRAMSys/traceAnalyzer/businessObjects/traceplotlinemodel.cpp index d05c51f2..b57b2f4f 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/traceplotlinemodel.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/traceplotlinemodel.cpp @@ -232,7 +232,10 @@ void SelectedTracePlotLineModel::recreateCollapseButtons(TracePlot *tracePlot, { // Remove old buttons for (auto button : collapseButtons) + { button->hide(); + button->deleteLater(); + } collapseButtons.clear(); @@ -243,7 +246,7 @@ void SelectedTracePlotLineModel::recreateCollapseButtons(TracePlot *tracePlot, QPushButton *collapseButton = new QPushButton(tracePlot); - unsigned int yVal = [&]() + unsigned int yVal = [node]() { if (node->data.collapsed) return node->data.yVal; @@ -270,7 +273,9 @@ void SelectedTracePlotLineModel::recreateCollapseButtons(TracePlot *tracePlot, recreateCollapseButtons(tracePlot, customLabelScaleDraw); }; - connect(customLabelScaleDraw, &CustomLabelScaleDraw::scaleRedraw, this, repositionButton); + // Important: The context of the connection is `collapseButton` as it should be disconnected when the button + // ceases to exist. + connect(customLabelScaleDraw, &CustomLabelScaleDraw::scaleRedraw, collapseButton, repositionButton); connect(collapseButton, &QPushButton::pressed, this, toggleCollapsed); connect(collapseButton, &QPushButton::pressed, tracePlot, &TracePlot::recreateCollapseButtons);