我对Qt的内存管理有些困惑。我正在查看一些入门样例和教程,看到了这个:
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自动处理了内存管理。从这段代码来看,我认为可能存在内存泄漏的问题,因为没有任何东西被释放。