Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Valgrind shows 23.5% memory leak for Qt lib on x86 platform
Forum Updated to NodeBB v4.3 + New Features

Valgrind shows 23.5% memory leak for Qt lib on x86 platform

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manav
    wrote on last edited by
    #1

    I compiled QT-4.7.2 source on x86 platform and wrote a sample application to display a small window with a quit button. The program exits normally when Quit button is clicked. I then ran Valgrind tool to detect memory leaks which shows significantly large memory leaks (about 23.5%) for such a small application.

    @[e518816@pe1800xs button]$ valgrind --leak-check=full --track-origins=yes --log-file=valgrind.log -v ./button@

    @==2340== HEAP SUMMARY:
    ==2340== in use at exit: 1,152,738 bytes in 9,640 blocks
    ==2340== total heap usage: 32,752 allocs, 23,112 frees, 4,918,688 bytes allocated
    ==2340==
    ==2340== Searching for pointers to 9,640 not-freed blocks
    ==2340== Checked 10,218,524 bytes
    @

    @==2340== LEAK SUMMARY:
    ==2340== definitely lost: 2,956 bytes in 11 blocks
    ==2340== indirectly lost: 241,467 bytes in 1,391 blocks
    ==2340== possibly lost: 428,024 bytes in 2,777 blocks
    ==2340== still reachable: 480,291 bytes in 5,461 blocks
    ==2340== suppressed: 0 bytes in 0 blocks
    ==2340== Reachable blocks (those to which a pointer was found) are not shown.
    ==2340== To see them, rerun with: --leak-check=full --show-reachable=yes
    ==2340==
    ==2340== ERROR SUMMARY: 1487 errors from 1362 contexts (suppressed: 5 from 1)@

    The qt application "source code":https://docs.google.com/leaf?id=0B0OyykTTTazCOTIxZDYyYmMtNDNkMy00YjgyLTkyMmEtMzVhNzgxMWMyNDgy&sort=name&layout=list&num=50 and full "valgrind log":https://docs.google.com/leaf?id=0B0OyykTTTazCYzVjNDQyNDItZDQ4MS00M2E5LWJmNjUtZGMyZjhiNDdkNWM4&sort=name&layout=list&num=50 file can be downloaded. Please help to resolve this memory leak issue as I want to port this application on a ARM9 based Freescale iMX target board with limited RAM.

    Thanks & Regards,
    Manavendra Nath Manav

    Thanks & Regards,
    Manavendra Nath Manav

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ifewalter
      wrote on last edited by
      #2

      What you should do, is make sure you delete all pointers you declare before the application closes (*quit, *desktop, *widget).

      --Ifewalter--

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Nah, meta object system should take care of that.

        Are you using separate Valgrind instance or this built-in in Qt Creator? I've heard there are some known false-positives popping up in valgrind, when checking any Qt app. The built-in version is "aware" of those pitfalls and does not report them.

        EDIT: havent tried that myself, though, so you may treat this post as gossiping ;)

        (Z(:^

        1 Reply Last reply
        0
        • M Offline
          M Offline
          manav
          wrote on last edited by
          #4

          I ran Valgrind instance with build-in Qt creator. The valgrind report again shows memory leak even with the suppressions file for Qt47 included. The build-in Qt creator actually uses the same /usr/bin/valgrind executable, the only difference being the use of suppressions file which restricts some leaks and conditions check from popping up in the report. The full log file is attached "here":https://docs.google.com/leaf?id=0B0OyykTTTazCNDM4MWEwZTctZTU2NS00NDgxLTg2MGYtODBhYjVhODJiM2Jl&sort=name&layout=list&num=50

          Thanks & Regards,
          Manavendra Nath Manav

          1 Reply Last reply
          0
          • M Offline
            M Offline
            manav
            wrote on last edited by
            #5

            After analyzing the Valgrind log, the functions causing the maximum memory leaks multiple times are:

            QFontDatabase::load() in libQtGui
            qHBNewFace() in libQtCore
            g_type_create_instance() in libgobject
            FT_Load_Glyph() in libfreetype
            XML_ParseBuffer() in libexpat

            In the above list, the functions q_type_create_instance() and qHBNewFace() has been called most of the times. From the attached valgrind log it appers that remaining memory leaks are result of functions using g_strdup and g_memdup which are not freed.

            Is my analysis in the right direction? Or, am I missing something here?

            Thanks & Regards,
            Manavendra Nath Manav

            Thanks & Regards,
            Manavendra Nath Manav

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved