Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
ThaRez last edited by
If I set a pixmap to a QLabel and the set another in the following fashion:
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.
veeraps last edited by
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.
lgeyer last edited by
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.
Jeroentjehome last edited by
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.