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.
db.open();
QString strQuery
= "SELECT DISTINCT " + field
+ " FROM " + table
+ str;
query.prepare(strQuery);
if(query.exec() == true)
{
while(query.next())
{
values.push_back(query.value(0).toString());
}
}
db.close();
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();
To copy to clipboard, switch view to plain text mode
Having experimented with I find the code below 'traps' less memory:
QString strQuery
= "SELECT DISTINCT " + field
+ " FROM " + table
+ str;
while(query.next())
{
values.push_back(query.value(0).toString());
}
QStringList values;
QString strQuery = "SELECT DISTINCT " + field + " FROM " + table + str;
QSqlQuery query(strQuery, db);
while(query.next())
{
values.push_back(query.value(0).toString());
}
To copy to clipboard, switch view to plain text mode
However, a small amount of memory is still not released. Has anyone else experienced anything like this? Comments?
Bookmarks