Results 1 to 18 of 18

Thread: QT Memory Leaks

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default QT Memory Leaks

    Hey everyone,

    I just finished my first QT application for displaying a directed graph. The only issue is that it seems to have a massive amount of memory leaks (~2400), even though I delete all of the objects that I create. I would be able to understand a smaller amount of leaks, but I can't fathom this many. Is there any reason that QT would cause such a huge amount of leaks?

    I'm fairly certain that its QT because I tested the leaks with multiple input files and number of nodes. One input file had about 20 nodes, while another had 4 or 5. For some reason, both files generated the same number of leaks. So that makes me think that the leak may be in QT due to the lack of scaling with the number of objects created.

    The other thought that I'm having is that this may be due to some incompatibility between QT and VLD. Some googling tells me this may be the case, does anyone have any experience with this or suggestions as to how to fix it?

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Memory Leaks

    Quote Originally Posted by lukabratzi View Post
    The only issue is that it seems to have a massive amount of memory leaks (~2400), even though I delete all of the objects that I create.
    Since measuring isn't only about the results but more importantly about how the measurement is done, can you give a description of how the measurement is done and how you get the number 2400?

  3. #3

    Default Re: QT Memory Leaks

    Sure, I'm not really sure what you mean by your question but I'll do my best to explain it.

    I just use #include "vld.h" at the top of my main function and run the program in debug mode. When it finishes execution vld outputs the status of my memory leaks. Its nothing that I did, just a library that I include in the source code.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Memory Leaks

    Yes, that's in the direction of my question.

    I don't know vld. Can you give a url please?

  5. #5

    Default Re: QT Memory Leaks

    Sure, here it is: VLD link

    There's a post at the bottom of the page called Qt that may be relevant. Its where I'm getting my assumption that the issue lies with QT/vld integrating

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT Memory Leaks

    VLD can support stack tracing of each leak, so you can see where the leaks are occuring from.

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Memory Leaks

    The problem you can have with in place (or in the code of your program itself) memory checking tools is the Heisenberg principle. When you are part of the system and you try to measure it, you will change the system.

    From onderstanding the posts on that site, the memory checking tool can be finished before the qt library is finished, resulting in false positives.

    On linux there's a tool called valgrind witch is not part of your program so it can measure more accurate

  8. #8

    Default Re: QT Memory Leaks

    Are there any windows alternatives to valgrind? My code was written on a windows pc and I don't currently have access to a linux pc.

    Also, the output from vld looks like this:
    0xFEEEFEEE (File and line number not available): (Function name unavailable)

    So I can't really trace the leaks and see where they're originating because vld can't tell me.

  9. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Memory Leaks

    If you want the stack traces to work, you also need to compile the Qt library in debug mode and link your program to the debug version of the Qt library.

  10. #10

    Default Re: QT Memory Leaks

    Oh okay, that explains a lot about the error messages. I'm currently compiling with visual studio 2008 using the qt plugin in debug mode. How can I compile/link to the qt library in debug mode?

  11. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Memory Leaks

    There's a configure option. Before you build the Qt library, you need to configure it. Use -debug (or something like that) instead of -release.
    Then, when it is installed, use the qmake of the debug version of the qt library. This qmake version will link to all the qt debug libraries.

    Thus:
    configure qt with -debug
    build it
    install it to a certain directory (example: c:\qtdebug)
    use qmake from this version (example: c:\qtdebug\bin\qmake c:\myproject\myproject.pro)

  12. #12
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT Memory Leaks

    But:
    Even then the stack traces won't be useful. You get a list of thousands of lines with no real information because all those objects are actually deleted after the report from your tool is done.

Similar Threads

  1. memory leaks detection in QT
    By kompotFX in forum Qt Programming
    Replies: 15
    Last Post: 28th January 2009, 21:29
  2. Memory Leaks
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2008, 16:26
  3. Memory leaks..
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2008, 19:28
  4. memory leaks
    By Fastman in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2008, 08:00
  5. why there are memory leaks in Qt?
    By cocalele in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2006, 09:55

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.