Skip to main content
GameDev.net gamedev.net
🔒 Locked

(c++) Easiest way of debugging leaks on windows?

Started by ........................................ Jul 2, 2009 at 11:27 AM 9 replies 2.7k views
fastcall22
fastcall22
Make your own?

#ifndef MEMCHECK_H#define MEMCHECK_H#if defined( _MSC_VER ) // Visual Studio only#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <crtdbg.h>#define new DEBUG_NEW#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )// Add in main():// _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );#endif // _MSC_VER#endif // MEMCHECK_H
Nypyren
Nypyren
There are a bunch of free solutions available if you search.
Quote:
Original post by Nypyren
There are a bunch of free solutions available if you search.


Maybe I didn't express myself properly: I did search for free solutions and I tried to get some to work (I am trying splint at the moment for example). But none got none of them to work, which surprised me since I remember using valgrind of linux which was very easy to get to work. So I thought I would ask here since someone might have a tip what the easiest way might be.

_fastcall: I'm using g++ and cant seem to get that example to work:

...#ifndef MEMCHECK_H#define MEMCHECK_H#if defined( _MSC_VER ) // Visual Studio only#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <crtdbg.h>#define new DEBUG_NEW#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )// Add in main():// _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );#endif // _MSC_VER#endif // MEMCHECK_Hint main ( int argc, char** argv ){	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );...


results in:

main.cpp:37: error: _CRTDBG_ALLOC_MEM_DF' was not declared in this scope
main.cpp:37: error:
_CRTDBG_LEAK_CHECK_DF' was not declared in this scope
main.cpp:37: error: `_CrtSetDbgFlag' was not declared in this scope
Driv3MeFar
Driv3MeFar
Quote:
Original post by philipptr
I'm using g++ and cant seem to get that example to work:


Quote:

#if defined( _MSC_VER ) // Visual Studio only


I would imagine not.
rioki
rioki
For win32 there is not free solution like valgrind. You can buy a license from bounds checker though, it only costs a fortune...

My solution is use valgrind on GNU/Linux and just hope that the win32 build does not introduce any additional leaks.

If you don't have that solution either use a existing compile in solution or build your own.
Rioki - http://www.rioki.org
Zakwayda
Zakwayda
@The OP: Is there any particular part of your code that you suspect is leaking memory? There are things that can be out of your control (such as third-party code that leaks memory), but as long as you follow good programming practices, it's fairly straightforward to write C++ code that can be virtually assured to be leak-free.
Kitt3n
Kitt3n
Try this one:

http://www.glowcode.com/

Do yourself a favor and read the docs however, it's kind of 'weird'
to wrap your head around it - trying to understand the output.

We found several leaks in our gameserver (and even were able to
pinpoint a leak in one of the network sdk's we are using and get
it fixed by the middleware provider).

Regards
visit my website at www.kalmiya.com
@jyk: had a very long search to find the leak wihtout debug tools and finally found a piece of code, where I freed variable twice instead of that one and a similar named one. After that I thought I still had a small leak, but it seems like windows was just too lazy to free all the memory properly. (Was about 2mb above what the memory usage should have been)

@Kitt3n: seems way to expensive for me as a student, but I might have a go at the trial version ;)

@rioki: I think I am going to install Linux again to do exactly the same thing you do ;)


Thanks for the help guys, I didn't make this thread because I was too lazy to search for solutions, but because I thought there might be a easy soution which I was missing.
yaustar
yaustar
Bit late for this but when I was at Uni, I used Visual Leak Detector which worked pretty well.

Edit: Just saw you are using GCC, my bad.
Steven Yau
[Blog] [Portfolio]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.