I'm getting a strange memory leak somewhere in this code. The method is a SLOT connected to a method in another thread. It does 2 things: 1 it updates a text box with the iteration that that the other thread is on. 2 it updates the image shown on the GUI to the image corresponding to that iteration.
It works great for 10-30 iterations, then blows up. Watching its memory usage in the task manager, I can see that it's steady at first, then each iteration increases the RAM usage by about 10%. What can I do to remove the leak?
Transition::Transition(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Transition)
{
ui->setupUi(this);
this->files = files;
imageObject = new QImage();
scene = new QGraphicsScene(this);
}
Transition::~Transition()
{
delete ui;
delete imageObject;
delete scene;
}
The SLOT in question:
void Transition::onCounterChanged(QString counter){
ui->imageCounter->setText(counter);
foldername = ui ->folderName->toPlainText();
int m = counter.toInt();
QString filename = files[m];
imageObject->load(filename);
image = QPixmap::fromImage(*imageObject);
scene->clear();//THIS FIXES THE LEAK
scene->addPixmap(image);
ui->picDisplay->setScene(scene);
ui->picDisplay->fitInView(image.rect(),Qt::IgnoreAspectRatio);
}