Memory leak?
-
Hello
If I set a pixmap to a QLabel and the set another in the following fashion:@imgLabel->setPixmap(QPixmap(":/img/on.png"));
imgLabel->setPixmap(QPixmap(":/img/off.png"));@Will this release all the memory or cause a memory leak? Also, is this the correct way och swapping images? and is there any downside? I'd like to avoid creating image pointers and reserving memory for the pixmaps with new, due to the considerable amount of "on/off" images.
-RS -
Looking at the declaration of "QLabel::setPixmap":http://qt-project.org/doc/qt-4.8/qlabel.html#pixmap-prop - it takes a constant reference to a QPixmap and looking at the definition, noticed that there is a QPixmap object is created with new and assigned to local pointer.
Before creating the new QPixmap, contents are cleared as well.
Hence, I think there wont be any memory leak, as memory management is properly done.
-
QPixmap is implicitly shared, thus I suggest to create the pixmap once [probably as a private (static) member of your class] and to pass the reference as required.
-
Since imglabel will be the owner of the QPixmap it will release all memory used. So no memory leak here. Qt is pretty strong in memory management.
-
image need 32bit