[Qt-interest] Memory management in Qt4 examples

Sarvesh Saran Sarvesh.Saran at synopsys.com
Wed Dec 3 07:54:38 CET 2008


Hi,

 

I was studying some of the Qt4 examples and have a doubt about dynamic
memory management?

 How does Qt manage dynamic memory?

 I noticed that in both the torrent example and the Mainwindow
(Application) examples there was extensive use of the new operator but
no corresponding delete operator.

 There was no destructor defined which could release memory.

 

I am little confused. In my application I create a variety of widget
objects on the heap...and I am deleting these resources in a slot called
closeApplication.

 

useri.menu_File->addAction(QIcon(":icons/exit.png"), tr("E&xit"), this,
SLOT(closeApplication()));

 

 

MainWindow::closeApplication()

{

        delete  x;

        delete y;

       As so on....

  this->close();  //does this ensure that the main window is deleted,
hence destroying all its members?

}

 

Or should I rather have a destructor and delete objects there?

 

Thanks,

Max.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081203/1524b857/attachment.html 


More information about the Qt-interest-old mailing list