Results 1 to 9 of 9

Thread: Memory leak detection

  1. #1
    Join Date
    Jun 2007
    Posts
    2

    Default Memory leak detection

    Hi,
    on linux there is valgrind to detect memory leak.
    But what tool (free/open source) can i use to detect memory leak on the open source version of QT4.3 with the mingw compiler.

    I have a C application (command line) that fireup at some point a QT4 dll interface.
    All the whole application (exe and dll) is compiled with mingw-gcc.
    It's a bit like VLC which have the QT4 interface as a DLL.

    My point here is to check for memory leak in the QT4 part.
    I've google so far, and i found one website :
    Wu Yongwei’s Programming Page
    But it seems not be working fine on QT4 objects.

    I know there is a tool called Purify from IBM which is not free and works better with Visual C++.
    I want to stick with mingw.

    Anyone can help here

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Memory leak detection

    Quote Originally Posted by Sid View Post
    I've google so far, and i found one website :
    Wu Yongwei’s Programming Page
    But it seems not be working fine on QT4 objects.
    What kind of problems did you encounter? I gave it a quick try and it seems to detect at least basic and obvious leaks just fine.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leak detection

    First of all, sorry for digging up such an old thread, but I figured it was better to continue this one than to make a new one.

    I'm trying to implement memory leak detection in my debug exe and for that I'm using the memory leak detector linked to in the original poster's post. However, I don't get any ouput. I'm guessing this is because my application is a GUI and I have no console window.

    I did some simple tests, like adding a "cout << "Test";" line to my app and if I run it like this from the command prompt: "testapp.exe > output.txt", it works just fine, console output gets written to output.txt upon exit. So, after thinking about complaining here for help I dug a little deeper .

    First, I tried changing line 149 of debug_new.h to:
    Qt Code:
    1. : _M_file(file), _M_line(line) { freopen("file_of_choice.txt", "w", new_output_fp); }
    To copy to clipboard, switch view to plain text mode 

    But, for some reason that didn't quite work. In case anyone knows why, feel free to let me know. I even added a cout test line in the constructor, but it doesn't seem to do anything, pretty weird.

    The simple solution is to edit line 281 of debug_new.cpp and change "stderr" to "stdout", so you can redirect the output to a file by simple calling your program from console with program.exe > outputfile.txt.

    If anyone knows a more graceful solution, let me know.

    Ok, this is newbie stuff, but still, it might save someone some time.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Memory leak detection

    Enable console by adding
    QT += console
    to .pro file and then re-build the application.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    Darhuuk (10th January 2008)

  6. #5
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leak detection

    Hm, that doesn't seem to work. When I add "console" I get an "undefined reference to 'WinMain@16'" error from libmingw32.a(main.o). Removing "windows" from CONFIG doesn't help either.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Memory leak detection

    Just rebuild the application:
    > make clean
    > make
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    Darhuuk (10th January 2008)

  9. #7
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leak detection

    Ah, ok, thanks, didn't know a rebuild required a make clean. It works now.

  10. #8
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leak detection

    I want to do the same, but it only shows the address of variable in memory, not the line of code:

    Leaked object at 003E6D80 (size 4, 004013CA)
    Leaked object at 003E6DE0 (size 10, 004013DA)
    *** 2 leaks found

    I understand there is program called addr2line for linux, but I'm on windows platform. How could I translate it?

    Thanks!

    Update: OK, i found it mingw32 folder. How should I use it on windows on executables?
    I have tried this addr2line -e <app.exe> 00415B82 and without address, but no meaningful output, just these:

    ??:0

    ??:0

    ??:0

    ??:0

    ??:0
    Last edited by falconium; 4th May 2011 at 17:42.

  11. #9
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leak detection

    OK, I should have used the debug version of the executable....

Similar Threads

  1. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 15:18
  2. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 20:42
  3. Memory Leak in Qt
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2007, 09:02
  4. Any reason for memory leak?
    By steg90 in forum Newbie
    Replies: 2
    Last Post: 10th May 2007, 16:00
  5. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 13:47

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.