Memory Leak Continued
There was some confusion with regard to my last blog about leaking memory. Suppose the ui_mywidget.h files looks like this:
class Ui_Widget
{
public:
QGridLayout *gridLayout;
QGroupBox *groupBox;
QGridLayout *gridLayout1;
QListWidget *listWidget;
QSpacerItem *spacerItem;
QPushButton *pushButton;
void setupUi(QWidget *Widget);
void retranslateUi(QWidget *Widget);
};Of course, those 6 QObject derived classes are deleted. But the sizeof(Ui_Widget) = 6 * sizeof(void*) = 24 bytes are not deleted. As Ui_Widget is not QObject derived those 24 bytes leak. Confirmed by valgrind.
In a comment to my last blog Paolo suggested to use auto_ptr or scoped_ptr, which is more elegant than an extra wrapper class :)