Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37

Thread: memory leak - where?

  1. #21
    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?

    Report like this?

    Qt Code:
    1. ==29102== 3,392 bytes in 143 blocks are possibly lost in loss record 371 of 380
    2. ==29102== at 0x4023C4C: malloc (vg_replace_malloc.c:195)
    3. ==29102== by 0x50146F3: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    4. ==29102== by 0x5019579: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    5. ==29102== by 0x501A982: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    6. ==29102== by 0x5368A54: ??? (in /usr/lib/libexpat.so.1.5.2)
    7. ==29102== by 0x53698A0: ??? (in /usr/lib/libexpat.so.1.5.2)
    8. ==29102== by 0x536ADB0: ??? (in /usr/lib/libexpat.so.1.5.2)
    9. ==29102== by 0x536B969: ??? (in /usr/lib/libexpat.so.1.5.2)
    10. ==29102== by 0x536264B: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.2)
    11. ==29102== by 0x50187FA: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.4.4)
    12. ==29102== by 0x5018B43: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.4.4)
    13. ==29102== by 0x501A038: ??? (in /usr/lib/libfontconfig.so.1.4.4)
    To copy to clipboard, switch view to plain text mode 

    It's from application where nothing happens - there's only window.

    Sorry I'm very stubborn about this memory leak but I've wrote some applications and all of them works fine on PC but on ARM after some time applications starting to work very slow and it looks like everything freezes (especially applications which uses SQLite databases). I suppose It's memory leak (applications are not complicated). Maybe I should look for cause somewhere else?

    thanks in advance
    best regards
    Tomasz
    Last edited by Tomasz; 1st September 2010 at 23:15.

  2. #22
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: memory leak - where?

    Wait - you suppose it's a memory leak? You're not sure? Why do you think it's a memory leak?

    You aren't going to find solutions to your problems unless you describe them correctly. Use a tool like 'top' to monitor your application's memory usage over time, and see if it increases indefinitely. Or if there's some runaway CPU process bogging down the system. Or try netstat if you're connecting to a remote server, to see if there's some aberrant network activity that might be causing the slowdown.

    Or, if you're really fixated on believing it's a memory issue, why not simply try destroying the connection you started off suspecting, and see if that makes the problem go away?

    Or you can continue to pore over the valgrind output, looking for bytes marked as definitely lost; as you can see, it provides references back to the line in your source code where the problem originated.

  3. #23
    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 SixDegrees View Post
    Use a tool like 'top' to monitor your application's memory usage over time, and see if it increases indefinitely.
    I've used 'top' and memory increases all the time the program works. Maybe someone could check my project (it's really short) because I have no idea what I'm doing wrong. I will be really grateful I can only guess it can by connected with databases...

    thanks in advance
    best regards
    Tomasz

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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?

    Does valgrind report leaks in your code?
    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.


  5. #25
    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?

    Yes It reports memory leaks as I said earlier. He reports it's connected with database functions (I'm still learning to use valgrind so I can't say nothing more now) but I know it happens mostly when I'm using functions that are doing something with database... so it would be nice if someone check my whole code because I think I'm doing the same mistake in every app...

    thanks in advance
    best regards
    Tomasz

  6. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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
    Yes It reports memory leaks as I said earlier. He reports it's connected with database functions (I'm still learning to use valgrind so I can't say nothing more now) but I know it happens mostly when I'm using functions that are doing something with database... so it would be nice if someone check my whole code because I think I'm doing the same mistake in every app...
    Please show us the relevant sections of the report and corresponding lines of your source code.
    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.


  7. #27
    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?

    Using valgrind for QT is very difficult. It report about 84000 errors (like "Conditional jump or move depends on uninitialised value(s)"). I really don't know what is important here. I was observing my program and I've noticed that memory is growing while I'm using function in code below.

    Qt Code:
    1. bool MainWindow::pobierzKomunikaty()
    2. {
    3. bool ok;
    4. QTextStream out(stdout);
    5. QString zapytanie;
    6. QSqlQueryModel queryModel;
    7. QSqlQuery query;
    8. QFont font;
    9.  
    10. font.setPointSize(7);
    11.  
    12. odczytanoOstatnieKomunikaty=0;
    13.  
    14. ok = bdb.open();
    15.  
    16. if (ok)
    17. {
    18. out << endl << "Otworzylem baze!" << endl ;
    19. } else {
    20. out << "Nie udalo sie otworzyc bazy!" << endl;
    21. }
    22.  
    23. queryModel.clear();
    24.  
    25. queryModel.setQuery("SELECT * FROM server_notifications WHERE complete='0'", bdb);
    26.  
    27. liczbaWiadomosci = queryModel.rowCount();
    28.  
    29. bdb.close();
    30.  
    31. #ifdef DEBUG
    32. out << "Mamy: " << liczbaWiadomosci << " wiadomosci!" << endl;
    33. #endif
    34.  
    35.  
    36. for(int i=0 ; i<liczbaWiadomosci; i++)
    37. {
    38. rec = queryModel.record(i);
    39.  
    40.  
    41. #ifdef DEBUG
    42. out << rec.value(1).toString() << ": ";
    43. out << rec.value(2).toString() << endl;
    44. #endif
    45.  
    46. QMessageBox *msgBox=new QMessageBox;
    47.  
    48. if(rec.value(1).toString()=="warning") msgBox->setIcon(QMessageBox::Warning);
    49. else if (rec.value(1).toString()=="info") msgBox->setIcon(QMessageBox::Information);
    50. else if (rec.value(1).toString()=="error") msgBox->setIcon(QMessageBox::Critical);
    51.  
    52. if(rec.value(1).toString()!="confirmation")
    53. {
    54. msgBox->setFont(font);
    55. msgBox->setWindowTitle(rec.value(1).toString());
    56. msgBox->setText(rec.value(2).toString());
    57.  
    58. QSpacerItem* horizontalSpacer = new QSpacerItem(240, 290, QSizePolicy::Minimum, QSizePolicy::Minimum);
    59. QGridLayout* layout = (QGridLayout*)msgBox->layout();
    60. layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
    61.  
    62. msgBox->move(0,0);
    63. msgBox->exec();
    64.  
    65. delete msgBox;
    66.  
    67. ok = bdb.open();
    68.  
    69. zapytanie.clear();
    70. zapytanie="update server_notifications set complete='1'";
    71. zapytanie.append(" where id='");
    72. zapytanie.append(QString::number(rec.value(0).toInt()));
    73. zapytanie.append("'");
    74.  
    75. query.clear();
    76. query.prepare(zapytanie);
    77. ok = query.exec();
    78. query.clear();
    79.  
    80. bdb.close();
    81. } else if (rec.value(1).toString()=="confirmation") {
    82. msgBox->setIcon(QMessageBox::Question);
    83. msgBox->setFont(font);
    84. msgBox->setWindowTitle(rec.value(1).toString());
    85. msgBox->setText(rec.value(2).toString());
    86. msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    87.  
    88. QSpacerItem* horizontalSpacer = new QSpacerItem(240, 290, QSizePolicy::Minimum, QSizePolicy::Minimum);
    89. QGridLayout* layout = (QGridLayout*)msgBox->layout();
    90. layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
    91.  
    92. msgBox->move(0,0);
    93. int result = msgBox->exec();
    94.  
    95. delete msgBox;
    96.  
    97. ok = bdb.open();
    98.  
    99. zapytanie.clear();
    100. if (result == QMessageBox::Yes) zapytanie="update server_notifications set complete='2'";
    101. else if (result == QMessageBox::No) zapytanie="update server_notifications set complete='3'";
    102. zapytanie.append(" where id='");
    103. zapytanie.append(QString::number(rec.value(0).toInt()));
    104. zapytanie.append("'");
    105.  
    106. query.clear();
    107. query.prepare(zapytanie);
    108. ok = query.exec();
    109. query.clear();
    110.  
    111. bdb.close();
    112. }
    113. }
    114.  
    115. zapytanie.clear();
    116. rec.clear();
    117. queryModel.clear();
    118. odczytanoOstatnieKomunikaty=1;
    119.  
    120. return ok;
    121. }
    122.  
    123. bool MainWindow::wyswietlKomunikaty()
    124. {
    125. if(odczytanoOstatnieKomunikaty==0)
    126. {
    127.  
    128. } else
    129. {
    130. pobierzKomunikaty();
    131. odczytajNotificationInterval();
    132. timer.start(notificationInterval);
    133. }
    134.  
    135. return 1;
    136. }
    137.  
    138. bool MainWindow::odczytajNotificationInterval()
    139. {
    140. bool ok;
    141. QTextStream out(stdout);
    142. QSqlQueryModel queryModel;
    143.  
    144. ok = bdb.open();
    145.  
    146.  
    147. if (ok)
    148. {
    149. out << endl << "Otworzylem baze!" << endl ;
    150. } else {
    151. out << "Nie udalo sie otworzyc bazy!" << endl;
    152. }
    153.  
    154. queryModel.clear();
    155.  
    156. queryModel.setQuery("SELECT * FROM config WHERE name='qt-notification-interval'", bdb);
    157.  
    158. rec = queryModel.record(0);
    159. notificationInterval = (rec.value(1).toInt())*1000;
    160.  
    161. #ifdef DEBUG
    162. out << "Notification interval: " << notificationInterval << " ms" << endl;
    163. #endif
    164.  
    165. rec.clear();
    166. queryModel.clear();
    167. bdb.close();
    168.  
    169. return ok;
    170. }
    To copy to clipboard, switch view to plain text mode 

    And really I can't say nothing more. Like I said valgrind generates thousands of messages for QT applications. Problem is important because when program runs on ARM it takes minute after minute more memory resources.

    thanks in advance
    best regards
    Tomasz

  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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?

    Here is an example app:
    Qt Code:
    1. #include <QtGui>
    2.  
    3.  
    4. int main(int argc, char **argv){
    5. QApplication app(argc, argv);
    6. QLineEdit *le = new QLineEdit;
    7. QString *str = new QString("xxx");
    8. le->setText(*str);
    9. le->show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    And valgrind report for it (the parts that are relevant):
    ==12196== HEAP SUMMARY:
    ==12196== in use at exit: 195,287 bytes in 2,848 blocks
    ==12196== total heap usage: 72,096 allocs, 69,248 frees, 10,244,645 bytes allocated
    ==12196==
    ==12196== 4 bytes in 1 blocks are definitely lost in loss record 27 of 566
    ==12196== at 0x40244F0: operator new(unsigned int) (vg_replace_malloc.c:214)
    ==12196== by 0x8048811: main (main.cpp:7)
    ==12196==
    ==12196== 16,548 (20 direct, 16,528 indirect) bytes in 1 blocks are definitely lost in loss record 566 of 566
    ==12196== at 0x40244F0: operator new(unsigned int) (vg_replace_malloc.c:214)
    ==12196== by 0x80487ED: main (main.cpp:6)
    ==12196==
    ==12196== LEAK SUMMARY:
    ==12196== definitely lost: 1,401 bytes in 19 blocks
    ==12196== indirectly lost: 16,548 bytes in 113 blocks
    ==12196== possibly lost: 60,653 bytes in 611 blocks
    ==12196== still reachable: 116,685 bytes in 2,105 blocks
    ==12196== suppressed: 0 bytes in 0 blocks
    ==12196== Reachable blocks (those to which a pointer was found) are not shown.
    ==12196== To see them, rerun with: --leak-check=full --show-reachable=yes
    ==12196==
    ==12196== For counts of detected and suppressed errors, rerun with: -v
    ==12196== ERROR SUMMARY: 135 errors from 135 contexts (suppressed: 123 from 9)
    You can see it immediately says where to look for problems. The rest of the reports in my case are either false positives or caused by Qt's dependencies (like KDE or 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.


  9. #29
    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

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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.


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

    Tomasz (5th September 2010)

  12. #31
    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

  13. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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.


  14. #33
    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

  15. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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.


  16. #35
    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; 6th September 2010 at 00:40.

  17. #36
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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.


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

    Tomasz (6th September 2010)

  19. #37
    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, 12:13
  2. Qt dll + memory leak
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2009, 14:28
  3. memory leak
    By mattia in forum Newbie
    Replies: 18
    Last Post: 16th January 2008, 11:22
  4. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 17:24
  5. Memory Leak in Qt
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2007, 09: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.