所以我對Qt的內存管理有些困惑。我一直在尋找在開始樣品和教程,看到這個Qt Widget內存管理
QApplication app(argc, argv);
QWidget window;
QLabel *label = new QLabel(QApplication::translate("windowlayout", "Name:"));
QLineEdit *lineEdit = new QLineEdit();
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(label);
layout->addWidget(lineEdit);
window.setLayout(layout);
window.setWindowTitle(
QApplication::translate("windowlayout", "Window layout"));
window.show();
return app.exec();
這是除了我沒有看到任何內存釋放時,他們創造的新部件就好了,現在這只是本教程,使他們不要混淆人或是由Qt自動處理內存管理。因爲看到這個,我不得不相信存在內存泄漏,因爲沒有任何東西被釋放。
呃,如果他們釋放他們,應用程序將不再存在。這些都是在應用程序關閉之前存在的頂級對象。 –