Results 1 to 20 of 37

Thread: memory leak - where?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: memory leak - where?

    I've checked program with valgrind. It produced hundreds of messages.

    It' starts with:
    Qt Code:
    1. ==27551== HEAP SUMMARY:
    2. ==27551== in use at exit: 6,339,826 bytes in 16,037 blocks
    3. ==27551== total heap usage: 239,607 allocs, 223,570 frees, 63,095,584 bytes allocated
    4. ==27551==
    5. ==27551== 2 bytes in 1 blocks are possibly lost in loss record 5 of 3,561
    6. ==27551== at 0x4023C4C: malloc (vg_replace_malloc.c:195)
    7. ==27551== by 0x50F2ED3: g_malloc (in /lib/libglib-2.0.so.0.2400.1)
    8. ==27551== by 0x510B768: g_strdup (in /lib/libglib-2.0.so.0.2400.1)
    9. ==27551== by 0x5121060: g_get_language_names (in /lib/libglib-2.0.so.0.2400.1)
    10. ==27551== by 0x51153F9: g_thread_init_glib (in /lib/libglib-2.0.so.0.2400.1)
    11. ==27551== by 0x50A360D: g_thread_init (in /usr/lib/libgthread-2.0.so.0.2400.1)
    12. ==27551== by 0x4CFEAF0: QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(_GMainContext*) (qeventdispatcher_glib.cpp:297)
    13. ==27551== by 0x427F4CF: QGuiEventDispatcherGlibPrivate::QGuiEventDispatcherGlibPrivate() (qguieventdispatcher_glib.cpp:171)
    14. ==27551== by 0x427F5C2: QGuiEventDispatcherGlib::QGuiEventDispatcherGlib(QObject*) (qguieventdispatcher_glib.cpp:186)
    15. ==27551== by 0x4246454: QApplicationPrivate::createEventDispatcher() (qapplication_x11.cpp:606)
    16. ==27551== by 0x4CD54B8: QCoreApplication::init() (qcoreapplication.cpp:555)
    17. ==27551== by 0x4CD5726: QCoreApplication::QCoreApplication(QCoreApplicationPrivate&) (qcoreapplication.cpp:476)
    To copy to clipboard, switch view to plain text mode 

    There are a lot of messages like that above not connected directly with my code. Bu I've found a lot of like this:

    Qt Code:
    1. [...]
    2.  
    3. ==27551== 24 bytes in 1 blocks are possibly lost in loss record 1,088 of 3,561
    4. ==27551== at 0x4023C4C: malloc (vg_replace_malloc.c:195)
    5. ==27551== by 0x7EFE9CA: sqlite3MemMalloc (sqlite3.c:12607)
    6. ==27551== by 0x7EC92CF: mallocWithAlarm (sqlite3.c:15910)
    7. ==27551== by 0x7EC93C7: sqlite3Malloc (sqlite3.c:15938)
    8. ==27551== by 0x7F1DF40: unixOpen (sqlite3.c:25494)
    9. ==27551== by 0x7EC8CF8: sqlite3OsOpen (sqlite3.c:12229)
    10. ==27551== by 0x7EEB2F3: sqlite3BtreeFactory (sqlite3.c:34537)
    11. ==27551== by 0x7EF4839: openDatabase (sqlite3.c:96157)
    12. ==27551== by 0x7EC6774: QSQLiteDriver::open(QString const&, QString const&, QString const&, QString const&, int, QString const&) (qsql_sqlite.cpp:533)
    13. ==27551== by 0x4039760: QSqlDatabase::open() (qsqldatabase.cpp:842)
    14. ==27551== by 0x804C91F: MainWindow::pobierzKomunikaty() (in /home/tomek/projekt/start-build-desktop/start) //important???
    15. ==27551== by 0x804E224: MainWindow::MainWindow(QWidget*) (in /home/tomek/projekt/start-build-desktop/start)
    16.  
    17. [...]
    18.  
    19. ==27551== 32 bytes in 1 blocks are possibly lost in loss record 1,480 of 3,561
    20. ==27551== at 0x4023C4C: malloc (vg_replace_malloc.c:195)
    21. ==27551== by 0x7EFE9CA: sqlite3MemMalloc (sqlite3.c:12607)
    22. ==27551== by 0x7EC92CF: mallocWithAlarm (sqlite3.c:15910)
    23. ==27551== by 0x7EC93C7: sqlite3Malloc (sqlite3.c:15938)
    24. ==27551== by 0x7ED6F4B: sqlite3HashInsert (sqlite3.c:19830)
    25. ==27551== by 0x7ED8CCC: sqlite3FindCollSeq (sqlite3.c:69693)
    26. ==27551== by 0x7EF35DC: createCollation (sqlite3.c:95936)
    27. ==27551== by 0x7EF4676: openDatabase (sqlite3.c:96137)
    28. ==27551== by 0x7EC6774: QSQLiteDriver::open(QString const&, QString const&, QString const&, QString const&, int, QString const&) (qsql_sqlite.cpp:533)
    29. ==27551== by 0x4039760: QSqlDatabase::open() (qsqldatabase.cpp:842)
    30. ==27551== by 0x804C91F: MainWindow::pobierzKomunikaty() (in /home/tomek/projekt/start-build-desktop/start)
    31. ==27551== by 0x804E224: MainWindow::MainWindow(QWidget*) (in /home/tomek/projekt/start-build-desktop/start)
    32. ==27551==
    33. ==27551== 32 bytes in 1 blocks are possibly lost in loss record 1,481 of 3,561
    34. ==27551== at 0x4023C4C: malloc (vg_replace_malloc.c:195)
    35. ==27551== by 0x7EFE9CA: sqlite3MemMalloc (sqlite3.c:12607)
    36. ==27551== by 0x7EC92CF: mallocWithAlarm (sqlite3.c:15910)
    37. ==27551== by 0x7EC93C7: sqlite3Malloc (sqlite3.c:15938)
    38. ==27551== by 0x7ED6F4B: sqlite3HashInsert (sqlite3.c:19830)
    39. ==27551== by 0x7ED8CCC: sqlite3FindCollSeq (sqlite3.c:69693)
    40. ==27551== by 0x7EF35DC: createCollation (sqlite3.c:95936)
    41. ==27551== by 0x7EF46FD: openDatabase (sqlite3.c:96143)
    42. ==27551== by 0x7EC6774: QSQLiteDriver::open(QString const&, QString const&, QString const&, QString const&, int, QString const&) (qsql_sqlite.cpp:533)
    43. ==27551== by 0x4039760: QSqlDatabase::open() (qsqldatabase.cpp:842)
    44. ==27551== by 0x804C91F: MainWindow::pobierzKomunikaty() (in /home/tomek/projekt/start-build-desktop/start)
    45. ==27551== by 0x804E224: MainWindow::MainWindow(QWidget*) (in /home/tomek/projekt/start-build-desktop/start)
    46.  
    47. [...]
    To copy to clipboard, switch view to plain text mode 

    And some like this:

    Qt Code:
    1. ==27551== 2,436 (256 direct, 2,180 indirect) bytes in 1 blocks are definitely lost in loss record 3,433 of 3,561
    2. ==27551== at 0x4023D47: realloc (vg_replace_malloc.c:476)
    3. ==27551== by 0x5270F56: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    4. ==27551== by 0x52719AC: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    5. ==27551== by 0x52720FB: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    6. ==27551== by 0x527231F: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    7. ==27551== by 0x5264A27: FcDefaultSubstitute (in /usr/lib/libfontconfig.so.1.4.4)
    8. ==27551== by 0x444849A: loadFc(QFontPrivate const*, int, QFontDef const&) (qfontdatabase_x11.cpp:1545)
    9. ==27551== by 0x444B8E5: QFontDatabase::load(QFontPrivate const*, int) (qfontdatabase_x11.cpp:1939)
    10. ==27551== by 0x4423C29: QFontPrivate::engineForScript(int) const (qfont.cpp:270)
    11. ==27551== by 0x443BD26: QFontMetricsF::leading() const (qfontmetrics.cpp:1190)
    12. ==27551== by 0x4359653: qt_format_text(QFont const&, QRectF const&, int, QTextOption const*, QString const&, QRectF*, int, int*, int, QPainter*) (qpainter.cpp:7738)
    13. ==27551== by 0x435A695: QPainter::drawText(QRect const&, int, QString const&, QRect*) (qpainter.cpp:5807)
    14.  
    15. [...]
    16.  
    17. ==27551== 4,872 (512 direct, 4,360 indirect) bytes in 2 blocks are definitely lost in loss record 3,483 of 3,561
    18. ==27551== at 0x4023D47: realloc (vg_replace_malloc.c:476)
    19. ==27551== by 0x5270F56: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    20. ==27551== by 0x52719AC: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    21. ==27551== by 0x52720FB: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    22. ==27551== by 0x527231F: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    23. ==27551== by 0x5264A27: FcDefaultSubstitute (in /usr/lib/libfontconfig.so.1.4.4)
    24. ==27551== by 0x444849A: loadFc(QFontPrivate const*, int, QFontDef const&) (qfontdatabase_x11.cpp:1545)
    25. ==27551== by 0x444B8E5: QFontDatabase::load(QFontPrivate const*, int) (qfontdatabase_x11.cpp:1939)
    26. ==27551== by 0x4423C29: QFontPrivate::engineForScript(int) const (qfont.cpp:270)
    27. ==27551== by 0x445FC39: QScriptLine::setDefaultHeight(QTextEngine*) (qtextengine.cpp:2009)
    28. ==27551== by 0x446F072: QTextLine::layout_helper(int) (qtextlayout.cpp:1756)
    29. ==27551== by 0x4470F82: QTextLine::setLineWidth(double) (qtextlayout.cpp:1601)
    30.  
    31. [...]
    To copy to clipboard, switch view to plain text mode 

    And the final summary looks like this:

    Qt Code:
    1. ==27551== LEAK SUMMARY:
    2. ==27551== definitely lost: 2,344 bytes in 11 blocks
    3. ==27551== indirectly lost: 11,360 bytes in 568 blocks
    4. ==27551== possibly lost: 4,787,191 bytes in 8,606 blocks
    5. ==27551== still reachable: 1,538,931 bytes in 6,852 blocks
    6. ==27551== suppressed: 0 bytes in 0 blocks
    To copy to clipboard, switch view to plain text mode 

    I haven't found any message connected directly with code. Functions mentioned in messages I've posted earlier.
    Any idea?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: memory leak - where?

    These are most likely false positives as you probably don't close the database connection gracefully when you exit your application, but that's ok. It could also be that the application crashes and that's why QCoreApplication's destructor doesn't have a chance to run. The rest of the leaks are unrelated to Qt and you can't do anything about them (apart from not using the offending libraries, such as fontconfig).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Tomasz (5th September 2010)

  4. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: memory leak - where?

    Quote Originally Posted by wysota View Post
    These are most likely false positives as you probably don't close the database connection gracefully when you exit your application, but that's ok. It could also be that the application crashes and that's why QCoreApplication's destructor doesn't have a chance to run. The rest of the leaks are unrelated to Qt and you can't do anything about them (apart from not using the offending libraries, such as fontconfig).
    My application should work for a long time without problems, but more it's works valgrind shows more memory leaks. I'm always closing database after using it with MyDatabse.close(); Is there anything more I can do to make my application more reliable?

    thanks in advance
    best regards
    Tomasz

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: memory leak - where?

    Quote Originally Posted by Tomasz View Post
    My application should work for a long time without problems, but more it's works valgrind shows more memory leaks.
    I don't think Valgrind will show you memory leaks while the program is running. A leak can only be detected with probability close to 100% when the application exits.

    I'm always closing database after using it with MyDatabse.close();
    There is also QSqlDatabase::removeDatabase() that frees all the resources.

    Is there anything more I can do to make my application more reliable?
    You need to interpret the memory leak report yourself and review your code to see if you are not leaking memory. Qt itself doesn't leak memory so if you really do have leaks (not that you think you do but that you are certain you do) then it's either in your code or in support libraries (such as db engines, font engines, etc.).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: memory leak - where?

    Quote Originally Posted by wysota View Post
    I don't think Valgrind will show you memory leaks while the program is running. A leak can only be detected with probability close to 100% when the application exits.
    You're right. I meant that it shows leaks after closing application.
    I'll try QSqlDatabase::removeDatabase() and let know how it works.

    thanks
    best regards
    Tomasz

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: memory leak - where?

    Quote Originally Posted by Tomasz View Post
    I'll try QSqlDatabase::removeDatabase() and let know how it works.
    Don't expect miracles, it won't make your problems go away and from practical point of view the use of this method is meaningless as in your case you'd only use it when exiting the application anyway so it won't prevent the application from leaking memory.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: memory leak - where?

    I think I've found problem. Here we've got code:

    Qt Code:
    1. ok = bdb.open();
    2.  
    3. if (ok)
    4. {
    5. queryModel.clear();
    6. queryModel.setQuery("SELECT * FROM notifi WHERE complete='0'", bdb);
    7. queryModel.clear(); // <----- with this everything is OK
    8. bdb.close();
    9. }
    To copy to clipboard, switch view to plain text mode 

    And now my question - why if I close my database without clearing QSqlQueryModel strange things happens (data is still there but memory usage is still growing up each time function is executed)? I need to close database for other programs but i need to use data that I've just read from database to QSqlQueryModel.

    thanks in advance
    best regards
    Tomasz
    Last edited by Tomasz; 5th September 2010 at 23:40.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: memory leak - where?

    Destructor of the model will call clear() for you so this is not a memory leak situation. Of course you shouldn't be closing a connection with an active query and you will get a warning on the console when doing so. You should clear all the queries and only then close the database connection.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    Tomasz (5th September 2010)

  11. #9
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: memory leak - where?

    Quote Originally Posted by wysota View Post
    Of course you shouldn't be closing a connection with an active query and you will get a warning on the console when doing so. You should clear all the queries and only then close the database connection.
    In this case I don't get any warning in my console. I'm only observing growing memory usage ('top' command), which disappears when I clean before closing. I'll think I need to learn more about using database in QT. I've got some questions about that problem but I'll search for answers in thread more connected with databases. Thanks!

    best regards
    Tomasz

Similar Threads

  1. Memory leak
    By yxtx1984 in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2010, 11:13
  2. Qt dll + memory leak
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2009, 13:28
  3. memory leak
    By mattia in forum Newbie
    Replies: 18
    Last Post: 16th January 2008, 10:22
  4. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 16:24
  5. Memory Leak in Qt
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2007, 08:02

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.