我在这里看Qt例子:
在构造函数中,他们有:
Window::Window()
{
editor = new QTextEdit(); // Memory leak?
QPushButton *sendButton = new QPushButton(tr("&Send message")); // Memory leak?
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
QHBoxLayout *buttonLayout = new QHBoxLayout(); // Memory leak?
buttonLayout->addStretch();
buttonLayout->addWidget(sendButton);
buttonLayout->addStretch();
QVBoxLayout *layout = new QVBoxLayout(this); // Memory leak?
layout->addWidget(editor);
layout->addLayout(buttonLayout);
setWindowTitle(tr("Custom Type Sending"));
}
Run Code Online (Sandbox Code Playgroud)
那些有评论的行
// Memory leak?
Run Code Online (Sandbox Code Playgroud)
不是那些内存泄漏?
如果是这样,既然Window类没有构造函数,那么我应该把所有这些变量(编辑器已经是)Window成员变量?
或者......当Qt超出范围时,内部"删除"那些成员变量?