PDA

View Full Version : QSqlQueryModel and memory consumption



lunatic fringe
4th February 2010, 09:51
Hello,

if i create a new insatance of a QSqlQueryModel (based on sqlite database) the amount of memory is not completely freed when deleting the object.



.
..
model = new QSqlQueryModel();
model->setQuery(query);
while(model->canFetchMore())
model->fetchMore();
..
delete model;



What is the correct way to do this?

tangential
5th February 2010, 01:09
Delete the query as well. Sqlite is a caching driver, so that iterating over the dataset, will cache the values, allocating memory to do so. So, the memory you're seeing "not freed" is actually memory coming from the query object.

lunatic fringe
5th February 2010, 09:16
Ho can i achieve that?
Tthere is no function to do that.

JohannesMunk
5th February 2010, 11:09
Try QSqlQuery::clear();

I had a big memory load on the mysql-server side, because I didn't clear queries soon enough. I use QtScript to handle the queries (lots of them) and they are not deleted until the garbage collector picks them up, which is too late for me, so I had to use clear manually. Maybe it helps you, too.

Johannes