[Qt-interest] Memory management in Qt4 examples

Anthony Serdyukov uksus70 at gmail.com
Wed Dec 3 08:37:08 CET 2008


Take a look at parent-child relationship documentation.
If some object is created as a child of another object, then it will
be deleted during parent's death.

2008/12/3 Sarvesh Saran <Sarvesh.Saran at synopsys.com>:
> 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.
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>



-- 
Regards,
Anthony




More information about the Qt-interest-old mailing list