Code::Blocks Forums

User forums => Help => Topic started by: staloysius333 on October 17, 2005, 10:54:54 pm

Title: Memory Leak Checkers for CB/ming gcc on XP
Post by: staloysius333 on October 17, 2005, 10:54:54 pm
Hi,  Does anyone know of a Memory Leak Checker for CB on XP using the gcc compiler called mingw32?

Thanks. :D
Title: Re: Memory Leak Checkers for CB/ming gcc on XP
Post by: thomas on October 18, 2005, 10:25:55 am
Hmm... sure I already did reply to this yesterday? Did I click on "Preview" by accident?

Most custom allocators or garbage collectors (for example the one by Hans Boehm) can be configured to act as leak detectors.
Also, there is some leak detector built into wxWidgets (though I haven't ever used it).

Whether you use gcc and XP or something else should not really matter. The only thing that *does* matter is that if you want to use a leak detector or a custom allocator in general inside a wxWindows project, you *must* #undef new. That is because wxWindows implements its own leak detector by redefining new with a macro. Highway to hell...
Title: Re: Memory Leak Checkers for CB/ming gcc on XP
Post by: Maxx on October 18, 2005, 11:28:01 am
If you are using wxwidgets in your project you might want to take a look at wx\include\msw\setup.h, there you can define that you want to debug your allocated memory. This works very well for me, altough I'm not sure if it will work with mingw at all (there is a comment within setup.h about mingw). Set wxUSE_DEBUG_CONTEXT, wxUSE_MEMORY_TRACING, wxUSE_GLOBAL_MEMORY_OPERATORS and wxUSE_DEBUG_NEW_ALWAYS to 1 and you should get some debug output (use a debugger to see these messages) if you forget to free any objects on the heap (with sourcefile and linenumber where you allocated them). Of course you need to compile the library and your program with __WXDEBUG__ enabled.
Title: Re: Memory Leak Checkers for CB/ming gcc on XP
Post by: grv575 on October 19, 2005, 05:48:18 am
The wx config file says the built in leak detection wxWidgets uses doesn't work with mingw gcc (so you need to use the vc++ compiler, but codeblocks doesn't compile cleanly under vc yet I believe).

You may want to look at mpatrol (C/C++) or dmalloc (for C) on windows and valgrind on linux.  Although, even with new undefined in the wx config file, mpatrol still reported spurious leaks which are probably the result of wxWidgets doing it's own memory pool management or something.  The output wasn't exactly useful.
Title: Re: Memory Leak Checkers for CB/ming gcc on XP
Post by: tiwag on October 19, 2005, 08:22:53 am
The wx config file says the built in leak detection wxWidgets uses doesn't work with mingw gcc (so you need to use the vc++ compiler, but codeblocks doesn't compile cleanly under vc yet I believe)....
it only works with the VC IDE with debugger , using the VC Toolkit 2003 isn't enough

i'm using VS 7.1 and have to say it is working very well with wx-widgets projects.
from inside codeblocks it doesn't work, because CB doesnt invoke the VC debugger,
but you can use CB as your favorite IDE and when it comes to debugging, just start
your executable with the VC debugger - this works