Results 1 to 4 of 4

Thread: QSqlQueryModel and memory consumption

  1. #1
    Join Date
    Feb 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlQueryModel and memory consumption

    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.

    Qt Code:
    1. .
    2. ..
    3. model = new QSqlQueryModel();
    4. model->setQuery(query);
    5. while(model->canFetchMore())
    6. model->fetchMore();
    7. ..
    8. delete model;
    To copy to clipboard, switch view to plain text mode 

    What is the correct way to do this?

  2. #2
    Join Date
    Dec 2009
    Location
    Brisbane
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel and memory consumption

    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.

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlQueryModel and memory consumption

    Ho can i achieve that?
    Tthere is no function to do that.

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel and memory consumption

    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
    Last edited by JohannesMunk; 5th February 2010 at 11:14.

Similar Threads

  1. About QSqlQueryModel
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 11th December 2009, 22:27
  2. Replies: 0
    Last Post: 17th November 2009, 21:19
  3. QTableView memory consumption
    By LordQt in forum Qt Programming
    Replies: 7
    Last Post: 9th December 2008, 16:51
  4. Pixmap memory consumption
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 29th November 2007, 15:35
  5. Tracking memory consumption of plugins.
    By spud in forum General Programming
    Replies: 3
    Last Post: 7th September 2007, 13:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.