Results 1 to 15 of 15

Thread: Qt 4.1 Memory Leak

  1. #1
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt 4.1 Memory Leak

    When I complime my qt project (VC++, using plugins, Win-XP) I saw interesting details about memory that my application used..
    It's very strange, while I _only_ press menu button or change focus from other application to mine, size of memory used by my application Up and Up!
    Is it Memory Leak, what do you think ?
    Succes is 5% of talent and 95% of work!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.1 Memory Leak

    very probable that its a memory leak.
    But we can't say with out the code.

  3. #3
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.1 Memory Leak

    It's mostly all examples.
    You can try to run pluginpaint example.
    Then wait & seek after memory used (I test in WinXP)
    Succes is 5% of talent and 95% of work!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt 4.1 Memory Leak

    That is the result of valgrind, a memory debugger, when running the plugandpaint example and doing some things like switching windows, painting something, using menu entries...

    I'm testing under Linux.
    Qt Code:
    1. valgrind --tool=memcheck --leak-check=full ./plugandpaint
    2. ==16772== Memcheck, a memory error detector for x86-linux.
    3. ==16772== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
    4. ==16772== Using valgrind-2.4.0, a program supervision framework for x86-linux.
    5. ==16772== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
    6. ==16772== For more details, rerun with: -v
    7. ==16772==
    8. ==16772== Conditional jump or move depends on uninitialised value(s)
    9. ==16772== at 0x1C229F47: store_to_database (in /usr/lib/libX11.so.6.2)
    10. ==16772==
    11. ==16772== Conditional jump or move depends on uninitialised value(s)
    12. ==16772== at 0x1C229F50: store_to_database (in /usr/lib/libX11.so.6.2)
    13. ==16772==
    14. ==16772== Conditional jump or move depends on uninitialised value(s)
    15. ==16772== at 0x1C229F9B: store_to_database (in /usr/lib/libX11.so.6.2)
    16. ==16772==
    17. ==16772== Conditional jump or move depends on uninitialised value(s)
    18. ==16772== at 0x1C229FA0: store_to_database (in /usr/lib/libX11.so.6.2)
    19. ==16772==
    20. ==16772== Syscall param write(buf) points to uninitialised byte(s)
    21. ==16772== at 0x1C470248: write (in /lib/libpthread-0.10.so)
    22. ==16772== Address 0x1C77F510 is 320 bytes inside a block of size 16384 alloc'd
    23. ==16772== at 0x1B904E9A: calloc (vg_replace_malloc.c:176)
    24. ==16772== by 0x1C1D0E09: XOpenDisplay (in /usr/lib/libX11.so.6.2)
    25. ==16772==
    26. ==16772== Syscall param writev(vector[...]) points to uninitialised byte(s)
    27. ==16772== at 0x1C6663AE: (within /lib/libc-2.3.6.so)
    28. ==16772== by 0x1C2036BD: _X11TransSocketWritev (in /usr/lib/libX11.so.6.2)
    29. ==16772== Address 0x1C77F45E is 142 bytes inside a block of size 16384 alloc'd
    30. ==16772== at 0x1B904E9A: calloc (vg_replace_malloc.c:176)
    31. ==16772== by 0x1C1D0E09: XOpenDisplay (in /usr/lib/libX11.so.6.2)
    32. ==16772==
    33. ==16772== ERROR SUMMARY: 90 errors from 6 contexts (suppressed: 86 from 2)
    34. ==16772== malloc/free: in use at exit: 974296 bytes in 7456 blocks.
    35. ==16772== malloc/free: 236588 allocs, 229132 frees, 66411306 bytes allocated.
    36. ==16772== For counts of detected errors, rerun with: -v
    37. ==16772== searching for pointers to 7456 not-freed blocks.
    38. ==16772== checked 1740280 bytes.
    39. ==16772==
    40. ==16772==
    41. ==16772== 20 bytes in 1 blocks are definitely lost in loss record 30 of 116
    42. ==16772== at 0x1B904368: malloc (vg_replace_malloc.c:130)
    43. ==16772== by 0x1C61D12F: strdup (in /lib/libc-2.3.6.so)
    44. ==16772== by 0x1BB33812: qt_init(QApplicationPrivate*, int, _XDisplay*, unsigned long, unsigned long) (in /usr/lib/qt4/libQtGui_debug.so.4.1.0)
    45. ==16772== by 0x1BAD0F4E: QApplicationPrivate::construct() (in /usr/lib/qt4/libQtGui_debug.so.4.1.0)
    46. ==16772== by 0x1BAD0B76: QApplication::QApplication(int&, char**) (in /usr/lib/qt4/libQtGui_debug.so.4.1.0)
    47. ==16772== by 0x804EE1C: (within /usr/share/doc/qt-4.1.0/examples/tools/plugandpaint/plugandpaint)
    48. ==16772== by 0x1C5CB554: __libc_start_main (in /lib/libc-2.3.6.so)
    49. ==16772== by 0x804EC50: (within /usr/share/doc/qt-4.1.0/examples/tools/plugandpaint/plugandpaint)
    50. ==16772==
    51. ==16772==
    52. ==16772== 68 bytes in 1 blocks are possibly lost in loss record 45 of 116
    53. ==16772== at 0x1B904E9A: calloc (vg_replace_malloc.c:176)
    54. ==16772== by 0x1B8F2148: allocate_dtv (in /lib/ld-2.3.6.so)
    55. ==16772== by 0x1B8F21FF: _dl_allocate_tls_storage (in /lib/ld-2.3.6.so)
    56. ==16772== by 0x1B8F2427: _dl_allocate_tls (in /lib/ld-2.3.6.so)
    57. ==16772== by 0x1C46B971: __pthread_initialize_minimal (in /lib/libpthread-0.10.so)
    58. ==16772== by 0x1C468314: ??? (crti.S:19)
    59. ==16772== by 0x1C467CEF: ??? (crti.S:32)
    60. ==16772== by 0x1B8EFB4D: call_init (in /lib/ld-2.3.6.so)
    61. ==16772== by 0x1B8EFCDD: _dl_init (in /lib/ld-2.3.6.so)
    62. ==16772== by 0x1B8E480E: (within /lib/ld-2.3.6.so)
    63. ==16772==
    64. ==16772==
    65. ==16772== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 56 of 116
    66. ==16772== at 0x1B904368: malloc (vg_replace_malloc.c:130)
    67. ==16772== by 0x1C67CEF8: (within /lib/libc-2.3.6.so)
    68. ==16772== by 0x1C67C7F3: __nss_database_lookup (in /lib/libc-2.3.6.so)
    69. ==16772== by 0x1B9201EB: ???
    70. ==16772== by 0x1B921DA4: ???
    71. ==16772== by 0x1C63C9E3: getpwuid_r (in /lib/libc-2.3.6.so)
    72. ==16772== by 0x1C63C45E: getpwuid (in /lib/libc-2.3.6.so)
    73. ==16772== by 0x1BB3D5AD: (within /usr/lib/qt4/libQtGui_debug.so.4.1.0)
    74. ==16772== by 0x1BB3D2E9: (within /usr/lib/qt4/libQtGui_debug.so.4.1.0)
    75. ==16772== by 0x1C0B2DCA: _SmcProcessMessage (in /usr/lib/libSM.so.6.0)
    76. ==16772==
    77. ==16772==
    78. ==16772== 2720 bytes in 1 blocks are possibly lost in loss record 105 of 116
    79. ==16772== at 0x1B905096: memalign (vg_replace_malloc.c:217)
    80. ==16772== by 0x1B8F21D1: _dl_allocate_tls_storage (in /lib/ld-2.3.6.so)
    81. ==16772== by 0x1B8F2427: _dl_allocate_tls (in /lib/ld-2.3.6.so)
    82. ==16772== by 0x1C46B971: __pthread_initialize_minimal (in /lib/libpthread-0.10.so)
    83. ==16772== by 0x1C468314: ??? (crti.S:19)
    84. ==16772== by 0x1C467CEF: ??? (crti.S:32)
    85. ==16772== by 0x1B8EFB4D: call_init (in /lib/ld-2.3.6.so)
    86. ==16772== by 0x1B8EFCDD: _dl_init (in /lib/ld-2.3.6.so)
    87. ==16772== by 0x1B8E480E: (within /lib/ld-2.3.6.so)
    88. ==16772==
    89. ==16772== LEAK SUMMARY:
    90. ==16772== definitely lost: 56 bytes in 2 blocks.
    91. ==16772== indirectly lost: 120 bytes in 10 blocks.
    92. ==16772== possibly lost: 2788 bytes in 2 blocks.
    93. ==16772== still reachable: 971332 bytes in 7442 blocks.
    94. ==16772== suppressed: 0 bytes in 0 blocks.
    95. ==16772== Reachable blocks (those to which a pointer was found) are not shown.
    96. ==16772== To see them, rerun with: --show-reachable=yes
    To copy to clipboard, switch view to plain text mode 
    Looks like everything is ok

    The Qt runtime allocates sometimes more memory to create new instances and releases these when they are no longer needed. An example are popup menus.

  5. #5
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.1 Memory Leak

    THanks for description.
    And one moment i saw (not so bad)
    When you minimize window? size of allocated memory changed to 1mb
    Perfect!
    Succes is 5% of talent and 95% of work!

  6. #6
    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: Qt 4.1 Memory Leak

    malloc/free: in use at exit: 974296 bytes in 7456 blocks.
    There is almost a megabyte on unfreed but reachable memory So there is a leak, but looks like it's not in Qt but rather somewhere in XLib and libc.

  7. #7
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.1 Memory Leak

    Quote Originally Posted by wysota
    There is almost a megabyte on unfreed but reachable memory So there is a leak, but looks like it's not in Qt but rather somewhere in XLib and libc.
    In most cases I think that's application allocate more memory
    Succes is 5% of talent and 95% of work!

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt 4.1 Memory Leak

    Quote Originally Posted by wysota
    There is almost a megabyte on unfreed but reachable memory So there is a leak, but looks like it's not in Qt but rather somewhere in XLib and libc.
    It's in several libraries, part of them Qt. But this kind of leak will probably not increase while your program is running because it could have been freed.

    I've attached another valgrind run with more details.
    Attached Files Attached Files

  9. #9
    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: Qt 4.1 Memory Leak

    Quote Originally Posted by blackliteon
    In most cases I think that's application allocate more memory
    The thing is this memory is unfreed upon program termination, which is considered a leak. I don't investigate how much memory does the process allocate during its life.

    BTW: "malloc/free: 236588 allocs, 229132 frees, 66411306 bytes allocated."

  10. #10
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.1 Memory Leak

    Quote Originally Posted by wysota
    The thing is this memory is unfreed upon program termination, which is considered a leak. I don't investigate how much memory does the process allocate during its life.

    BTW: "malloc/free: 236588 allocs, 229132 frees, 66411306 bytes allocated."
    Sure you right!
    Succes is 5% of talent and 95% of work!

  11. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt 4.1 Memory Leak

    We need another tool here: Valgrind gives only total statistics not time samples and peak memory usage. Does anybody know of such a tool?

  12. #12
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.1 Memory Leak

    Quote Originally Posted by Codepoet
    We need another tool here: Valgrind gives only total statistics not time samples and peak memory usage. Does anybody know of such a tool?
    You mean memory leak or speed ?
    Succes is 5% of talent and 95% of work!

  13. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt 4.1 Memory Leak

    Valgrind is slow, yes - but that is not the reason: Valgrind does not collect statistics about things like:
    • maximum amount of memory used
    • memory usage while the application runs
    • graph of used memory by elapsed time

    These 66MB are the total amount of memory the program allocated during the whole run. But we are interested in how much did it use at any given time. That is a big difference since memory is freed again, then allocated and so on. We have many short lived objects.

    At the moment I'm trying memprof but it crashes

  14. #14
    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: Qt 4.1 Memory Leak

    Limit resources which can be given to a single process to a known amount, and you'll get info if the limit was met. See manual for ulimit for details. Or try mpatrol. Or do your own statistics, for example by overriding new and delete and using LD_PRELOAD.

  15. #15
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt 4.1 Memory Leak

    When running plugandpaint under mpatrol it's horribly slow, even slower then valgrind. Somewhere in mpatrol seems to be a bug because I constantly get errors about memmove on freed memory
    Nevertheless I've got some numbers: around 3.5 MB peak memory usage of plugandpaint


    I'll probably write my own library because I need one for my own job in the long term.

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 23:38
  2. memory leak question
    By cool_qt in forum General Programming
    Replies: 3
    Last Post: 20th January 2009, 08:49
  3. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 19:51
  4. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 15:18
  5. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 20:42

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.