我的代码会增加一些内存,原因是什么?

时间:2018-04-09 18:29:03

标签: qt memory-leaks

这是表格清洁代码:

void AudioAPI::clearTable(QTableWidget *songTable)
{
    songTable->clearContents();
    songTable->setRowCount(0);
}

第二

void AudioAPI::createSongFromPath(QString path, QTableWidget *songTable)
{
    TagLib::FileRef file(path.toLocal8Bit().data());

    TagLib::String title = file.tag()->title();
    TagLib::String artist = file.tag()->artist();

    songTable->insertRow(songTable->rowCount());
    songTable->setItem(songTable->rowCount() - 1, 0, new QTableWidgetItem(QString::fromStdWString(title.toWString())));
    songTable->setItem(songTable->rowCount() - 1, 1, new QTableWidgetItem(QString::fromStdWString(artist.toWString())));
    songTable->setItem(songTable->rowCount() - 1, 2, new QTableWidgetItem(path));
}

第3名(包含第2名和第1名):

void AudioAPI::createListFromDir(QString path, QTableWidget *songTable)
{
   if (path != NULL)
   {
       bool check = 0;
       QDirIterator it(path, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectories);

       while (it.hasNext())
       {
           if (!check)
           {
               AudioAPI::clearTable(songTable);
               check = 1;
           }
           it.next();
           createSongFromPath(it.filePath(), songTable);
       }
   }
}

多次运行第三个代码导致内存增加,我不知道它是由我的编码不当还是技术故障引起的。感谢任何帮助向我展示问题的关键点。

0 个答案:

没有答案