我一直在寻找的Qt例子here: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"));
}
与评论
// Memory leak?
不是那些内存泄漏那些行?如果是这样,由于Window类没有构造函数,那么我应该使所有这些变量(编辑器已经是)窗口成员变量?
Or..does Qt内部“删除”这些成员变量,当它超出范围?
+1我在猜测我的删除答案:) – AraK 2009-10-30 18:53:59