Results 1 to 20 of 37

Thread: memory leak - where?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: memory leak - where?

    Except the database issue, yes. But in general it's best to run your code through memory leak detection tool such as valgrind and see what it has to say.
    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.


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

    Tomasz (1st September 2010)

  3. #2
    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'll check it with valgrind. Is it necessary to use removeDatabase if I'm adding it only once at the beginning and then only using open/close on that database? Should I remove it and add it again after every open/close cycle?

    thanks in advance
    best regards
    Tomasz

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

    Default Re: memory leak - where?

    If you add it once then you remove it once. You said your application was increasing its memory usage and you gave the code snippet where you suspected the leak to be so I assumed it was being ran multiple times. We don't consider a leak something that lives throughout the whole life of the application and is not deleted anywhere (although it's still considered "improper"). A leak is when you repeat this process thoughout the life of the application, like so:
    Qt Code:
    1. for(int i=0;i<10;i++){
    2. QString *var = new QString("xxx"); // memory is allocated 10 times and never released although the variable is not reachable anymore
    3. }
    To copy to clipboard, switch view to plain text mode 
    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. #4
    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 used valgrind, and it says:

    Qt Code:
    1. LEAK SUMMARY:
    2. definitely lost: 768 bytes in 4 blocks
    3. indirectly lost: 2,840 bytes in 141 blocks
    4. possibly lost: 1,119,616 bytes in 4,885 blocks
    5. still reachable: 585,094 bytes in 5,456 blocks
    6. suppressed: 0 bytes in 0 blocks
    To copy to clipboard, switch view to plain text mode 

    Maybe I can post full code of my app (it's not long) and someone could tell me what I'm doing wrong?

    thanks in advance
    best regards
    Tomasz

    P.S. Even if I run the simplest application valgrind says that some memory is lost, but not as much as above.

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

    Default Re: memory leak - where?

    Rerun valgrind with --leak-check=full --show-reachable=yes
    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. #6
    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 ran it with that options for a while and it says:

    Qt Code:
    1. LEAK SUMMARY:
    2. definitely lost: 1,792 bytes in 8 blocks
    3. indirectly lost: 8,400 bytes in 418 blocks
    4. possibly lost: 5,756,014 bytes in 7,557 blocks
    5. still reachable: 1,967,661 bytes in 8,582 blocks
    6. suppressed: 0 bytes in 0 blocks
    To copy to clipboard, switch view to plain text mode 

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

    Quote Originally Posted by Tomasz View Post
    I've ran it with that options for a while and it says:

    Qt Code:
    1. LEAK SUMMARY:
    2. definitely lost: 1,792 bytes in 8 blocks
    3. indirectly lost: 8,400 bytes in 418 blocks
    4. possibly lost: 5,756,014 bytes in 7,557 blocks
    5. still reachable: 1,967,661 bytes in 8,582 blocks
    6. suppressed: 0 bytes in 0 blocks
    To copy to clipboard, switch view to plain text mode 
    Well, it says a good deal more than that. Valgrind gives you a detailed report not only on the total amount of memory leaked, but where it was leaked, right down to the line number. You'll want to compile in debug mode to get the best report, but even without debugging information it's usually possible to track down the portion of code responsible for a leak.

    Read through the valgrind documentation so you know what you're looking at.

  9. #8
    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
    Well, it says a good deal more than that.
    Yes, It says really a lot of things. Sometimes it says about errors even in 'clean' application (window only) just created in Qt Creator. I don't have a lot of experience with valgrind, I'm reading documentation but still have no idea how to track that leaks. Code looks fine for me.

    thaks in advance
    best regards
    Tomasz

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

    Default Re: memory leak - where?

    Sometimes you can get false positives so it's important to understand why certain things are reported. But you should get a very detailed output with a place in code and reason for every leak.
    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. #10
    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 22:15.

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

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

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
  •  
Qt is a trademark of The Qt Company.