Qt objects which are allocated with new
are pretty much handled for you. Things will get cleaned up at some point (almost always when the parent gets destructed) because Qt objects have a nice parent child relationship.
So my question is this: given that some widgets exist for the life of the application, is it considered good/beneficial to limit the scope of some child widgets? It seems to me that if I don't the application may not release these objects until the application exits. For example:
MyMainWindow::contextMenu(...) {
QMenu *menu = new QMenu(this);
// ...
menu->exec();
}
vs:
MyMainWindow::contextMenu(...) {
QMenu *menu = new QMenu(this);
// ...
menu->exec();
delete menu;
}
vs:
MyMainWindow::contextMenu(...) {
QScopedPointer<QMenu> menu(new QMenu(this));
// ...
menu->exec();
}
I like the last one the best, i know that that menu object will be cleaned up immediately, without adding any lines of code to worry about. But, in the first one, it should be cleaned up eventually. Am I wasting my effort trying to manage the lifetime of these Qt widgets? Should I just leave it up to Qt entirely?