I have a question about memory leak in Qt.
I have a QMainWindow with 2 QPushButtons.
First beep of a button:
m_label = new QLabel(this);
QPixmap pix(this->size());
QPainter painter;
painter.begin(&pix);
QImage img("1.png");
painter.drawPixmap(this->rect(), QPixmap::fromImage(img));
m_label->setPixmap(pix);
painter.end();
Signal for pressing the Secont button:
delete m_label;
When I run the test application, the allocated memory is about 11900 Kb. When I click on the first button, then the allocated memory for the application is about 12450 Kb. When I click on the second button, I got the allocated memory about 12250 Kb.
Why didn’t I get the same 11900 Kb? Is this a leak?
So, if you write the following code:
QImage img("1.png");
QImage img1("1.png");
QImage img2("1.png");
QImage img3("1.png");
QImage img4("1.png");
QImage img5("1.png");
QImage img6("1.png");
QImage img7("1.png");
QImage img8("1.png");
QImage img9("1.png");
Then, the allocated memory grows, but does not decrease. What for? How to clear this memory leak?
source
share