johnnyturbo3
13th July 2011, 16:10
Hi,
I'm checking the memory usage of an application I've made. It makes numerous calls to read and write values to and from a database. I've observed the following:
* QSqlQuery::exec() uses some KB of RAM to execute a given query, but does not release the memory after it goes out of scope.
* QSqlDatabase:: open() & close() do not help free resources as the documentation suggest. If anything, close() causes resources (at least memory) to remain 'trapped' on the heap/stack.
For example, here is a typical segment of code I've been using to access my database.
QStringList values;
db.open();
QString strQuery = "SELECT DISTINCT " + field + " FROM " + table + str;
QSqlQuery query(db);
query.prepare(strQuery);
if(query.exec() == true)
{
while(query.next())
{
values.push_back(query.value(0).toString());
}
}
db.close();
Having experimented with I find the code below 'traps' less memory:
QStringList values;
QString strQuery = "SELECT DISTINCT " + field + " FROM " + table + str;
QSqlQuery query(strQuery, db);
while(query.next())
{
values.push_back(query.value(0).toString());
}
However, a small amount of memory is still not released. Has anyone else experienced anything like this? Comments?
I'm checking the memory usage of an application I've made. It makes numerous calls to read and write values to and from a database. I've observed the following:
* QSqlQuery::exec() uses some KB of RAM to execute a given query, but does not release the memory after it goes out of scope.
* QSqlDatabase:: open() & close() do not help free resources as the documentation suggest. If anything, close() causes resources (at least memory) to remain 'trapped' on the heap/stack.
For example, here is a typical segment of code I've been using to access my database.
QStringList values;
db.open();
QString strQuery = "SELECT DISTINCT " + field + " FROM " + table + str;
QSqlQuery query(db);
query.prepare(strQuery);
if(query.exec() == true)
{
while(query.next())
{
values.push_back(query.value(0).toString());
}
}
db.close();
Having experimented with I find the code below 'traps' less memory:
QStringList values;
QString strQuery = "SELECT DISTINCT " + field + " FROM " + table + str;
QSqlQuery query(strQuery, db);
while(query.next())
{
values.push_back(query.value(0).toString());
}
However, a small amount of memory is still not released. Has anyone else experienced anything like this? Comments?