If I declare the query as a pointer or an object in a function, as far as I know (by reading the documentation), when the function stop (i.e. go to its end), the query is destroyed and [I image and hope] the memory occupied is released.
No. If you allocate something on the heap, i.e. with
qry = new QSqlQuery("SELECT ...", db);
To copy to clipboard, switch view to plain text mode
then you are responsible for ensuring that it is deleted at the corrected time. If you do not ensure deletion you have the classic memory leak you are describing. You can ensure deletion of QObjects by giving them a suitable parent at creation. QSqlQuery is not a QObject so you have to ensure deletion yourself (in a destructor, explicitly at the end of the function etc.).
There is generally no reason to allocate a QSqlQuery on the heap though.
Bookmarks