Qt sqlite 查询内存泄漏

       QSqlDatabase db;
       if(QSqlDatabase::contains("test"))
           db = QSqlDatabase::database("test");
       else
           db = QSqlDatabase::addDatabase("QSQLITE", "test");
       db.setDatabaseName("black.db");
       if(!db.open())
       {
           QSqlDatabase::removeDatabase("QSQLITE");
           return ;
       }
       QTime    tmpTime;
       tmpTime.start();
       QSqlQuery query(db);
       query.exec("select  * from pixdata where card='1000123'");
       int x= 0;
       while(query.next())
       {
           x  = query.value(0).toInt();
           qDebug()<<query.value(0).toInt()<<query.value(1).toString();
       }
       qDebug()<<"time"<<tmpTime.elapsed()<<"ms";
       //query.clear();
       db.close();
       QSqlDatabase::removeDatabase("QSQLITE");

这样查询时任务管理器里查看,内存一直往上增加

加了query.clear() 就正常了

Clears the result set and releases any resources held by the query. Sets the query state to inactive. You should rarely if ever need to call this function.

有道翻译:清理和释放结果集查询持有的任何资源。查询状态设置为不活跃。你应该几乎从不需要调用这个函数。

    原文作者:qcgao
    原文地址: https://blog.csdn.net/gaobobo138968/article/details/52176274
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞