Results 1 to 6 of 6

Thread: SQLQuery usage of RAM

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default SQLQuery usage of RAM

    Hello!

    I'm developing an application that 'do queries to a' MySQL.

    As far as I know, all times that I instantiate a new query and do a research in the MySQL server, the data returns and is stored in the query object, and from that it is read. No problems in that; the software runes fine.

    The problem is about the memory that is occupied with the data received fromt he MySQL. 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. But what if I declare the query as a global variable (which is the case in my app), so the query is never destroyed? In this case, does all search and data reception is stored in the RAM memory and never goes out till the software is closed (so the query used memory never stop growing)?


    -
    I'm doing this question because my software is time-by-time growing the used RAM memory in the computer, so after 2 days or more the free memory goes out and the computer "crashes". And now I have to find in a 16 million lines of code software what is causing this RAM problem. What is most interesting, however, is that even if the software is closed, the increased used RAM memory is not released!
    -


    Thanks,


    Momergil

  2. #2
    Join Date
    Mar 2012
    Location
    Lesotho
    Posts
    33
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: SQLQuery usage of RAM

    instead why don't you declare your connecion as glabal and create query object only when needed?

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLQuery usage of RAM

    If you're talking about QSqlQuery and QSqlDatabase then you should have no problems and you should not be using pointers or global objects.

    If you're talking about sql in general, then it's wrong place to ask the question as answer depends on what you're using

    In general, query should hold only results of last executed statement.
    Unless there's leak in the query object itself, you should not see memory gorowing infinitely.

  4. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQLQuery usage of RAM

    kito, to be sincere the software was developed by a former job colegue and I simply don't know why he decided to create global queries >.< In my softwares I always use as you sad.

    Quote Originally Posted by Spitfire View Post
    If you're talking about QSqlQuery and QSqlDatabase then you should have no problems and you should not be using pointers or global objects.

    If you're talking about sql in general, then it's wrong place to ask the question as answer depends on what you're using

    In general, query should hold only results of last executed statement.
    Unless there's leak in the query object itself, you should not see memory gorowing infinitely.
    Well, actually I'm [unfortunately] using Borland C++ Builder 6 with ZEOS library, but the documentation is so terrible that I guessed maybe things would be equal in Qt and Builder in this point.

    In any case, it's nice to hear about Qt since I'm developing another software in Qt that uses MySQL as well.


    Anyway, no problems. I was already figuring out that this wasn't my software's problem =]


    Thanks, God bless,


    Momergil

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SQLQuery usage of RAM

    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
    Qt Code:
    1. 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.

  6. #6
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQLQuery usage of RAM

    Ok Chris,

    thanks!


    Momergil

Similar Threads

  1. from sqlquery to qstringlist
    By ditsikts in forum Newbie
    Replies: 4
    Last Post: 4th February 2016, 18:18
  2. Replies: 7
    Last Post: 2nd April 2012, 23:35
  3. sqlQuery executing return nothing
    By ar_a24 in forum Qt Programming
    Replies: 0
    Last Post: 26th February 2011, 06:04
  4. SQLQUERY - column value retrun problem
    By damodharan in forum Qt Programming
    Replies: 7
    Last Post: 27th May 2010, 07:09
  5. Casting in a select sqlQuery
    By Kesy in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2008, 15:12

Tags for this Thread

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.