1 Attachment(s)
What to free or not to free, that is the question
When creating widgets in Qt, what do I need to free. Once I do the mainWidget.setLayout(layoutName), do I need to free any memory other than the widget itself? What about icon.setIcon(), does it take over the memory management for the icon?
I'll just include a sample file. Have I forgotten to free anything in the attached module, as long as I free the parent widget in the calling routine?
- BRC
Re: What to free or not to free, that is the question
Everything seems OK with your code.
Also take a look at: http://www.qtcentre.org/forum/f-qt-p...ion--5956.html
Generally you don't need to delete widgets, only in special cases when you allocate temporary widgets without a parent on the heap.
Also you might allocate QObject's on the heap, like a QList, QThread,ect. These are better to explicitly be deleted when finished using.
About setIcon: you can only pass a reference to this function, so if you have something like this:
Code:
setIcon(*icon);
...
delete icon;
You must delete the icon, since the for which you set it owns a copy of your icon.
Regards
Regards