Commit 66b75ec1 authored by Agata Cacko's avatar Agata Cacko

Fix memory leaks in KisMergeLabeledLayersCommand

Before this commit, KisMergeLabeledLayersCommand would keep the image
and paint device for as long as it is kept in the undo stack.
It's not needed, because the undo uses different ways to determine how
to undo and redo the selection.
After this commit at the end of the merge the command will clear its
shared pointer, which will in turn ensure that those objects will be
removed when nothing else will be using them.
parent d0efb113
......@@ -25,7 +25,7 @@
#include "kis_image.h"
#include "kis_painter.h"
#include "kis_layer.h"
#include "KisDeleteLaterWrapper.h"
......@@ -50,7 +50,9 @@ void KisMergeLabeledLayersCommand::undo()
void KisMergeLabeledLayersCommand::redo()
{
mergeLabeledLayers();
if (m_refImage) {
mergeLabeledLayers();
}
KUndo2Command::redo();
}
......@@ -107,6 +109,16 @@ void KisMergeLabeledLayersCommand::mergeLabeledLayers()
m_refImage->waitForDone();
KisPainter::copyAreaOptimized(QPoint(), m_refImage->projection(), m_refPaintDevice, m_refImage->bounds());
// release resources: they are still owned by the caller
// (or by some other object the caller passed them to)
m_refPaintDevice.clear();
m_currentRoot.clear();
// KisImage should be deleted only in the GUI thread (it has timers)
makeKisDeleteLaterWrapper(m_refImage)->deleteLater();
m_refImage.clear();
}
bool KisMergeLabeledLayersCommand::acceptNode(KisNodeSP node)
......
......@@ -146,6 +146,9 @@ void KisSelectionToolHelper::selectPixelSelection(KisProcessingApplicator& appli
savedCommand = transaction.endAndTake();
pixelSelection->setDirty(dirtyRect);
// release resources: transaction will care about
// undo/redo, we don't need the selection anymore
m_selection.clear();
}
if (m_view->selection()->selectedExactRect().isEmpty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment