• Memory Leak Continued

    by  • November 22, 2007 • Developers

    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 :)

    About

    Dominik is a PhD student at the Control Theory and Robotics Lab, TU Darmstadt, as part of the Research Training Group GKMM (GRK1362). My research focuses on state estimation in distributed systems. As hobby, I contribute to the KDE project and work on the Kate application and editor component.

    http://www.kate-editor.org