我试图强调我的程序,它基本上用不同数量的行更新 QTableWidget
每次我做一些动作时,我都想修改表格的大小,但在它之前如果想清除它并用它来清除它的单元格内容。
我正在经历的是,从我的资源监视器监控的堆只会增加。
这是我在应用程序中按下按钮时运行的部分代码:
MyClass::updateTable(int nrows)
{
ui->tableWidget->clearContents(); // this is to free the memory but the heap always grows
for (int i=0; i<nrows; i++)
{
// I don't like this new I don't know when the destructor is called here!!
QTableWidgetItem *item = new QTableWidgetItem();
item->setText("SOMETEXT");
ui->tableWidget->setItem(i,0,idItem);
}
}
从 指定的行数 int nrows
是一个非常可变的数字(从 10 到 10^5 )。
如何从堆中完全清除内存?