Jump to content
  • Advertisement
Sign in to follow this  
gumpy

[msvc++] enabling memory leak detection

This topic is 4669 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i decided to check out the built-in memory leak detection for vc++ and going by this page on msdn. i typed up a quick test:
#define CRTDBG_MAP_ALLOC
#include <cstdlib>
#include <crtdbg.h>

int main(int argc, char *argv[])
{
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	char *c = new char;
	return EXIT_SUCCESS;
}


here is the output:
Detected memory leaks!
Dumping objects ->
{42} normal block at 0x00320FF0, 1 bytes long.
 Data: < > CD 
Object dump complete.
according to that page on msdn:
Quote:
With _CRTDBG_MAP_ALLOC defined, the display also shows you the file where the leaked memory was allocated.
i must be overlooking something. why isn't it giving me the file name and line number? edit: sorry if this is the wrong forum. wasn't sure if i should post this here or general programming.

Share this post


Link to post
Share on other sites
Advertisement
dumb typo mistake on my part...

#define _CRTDBG_MAP_ALLOC
#include <cstdlib>
#include <crtdbg.h>

int main(int argc, char *argv[])
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
char *c = new char;
return EXIT_SUCCESS;
}


output is now:

Detected memory leaks!
Dumping objects ->
c:\program files\microsoft visual studio .net 2003\vc7\include\crtdbg.h(689) : {42} normal block at 0x00320FF0, 1 bytes long.
Data: < > CD
Object dump complete.

i was under the impression that it would point to the line "char *c = new char;". is there a way to do this?

Share this post


Link to post
Share on other sites
apparently i can't read tonight. this is for detecting leaks with malloc/free. is there a method for doing this with new/delete?

Share this post


Link to post
Share on other sites
finally solved my own problem after some searches. i'm not sure if this is the proper way to do it, but it seems to work. i'm posting since somebody may find this useful.

#define _CRTDBG_MAP_ALLOC
#include <cstdlib>
#include <crtdbg.h>
#ifdef _DEBUG
#define new new( _CLIENT_BLOCK, __FILE__, __LINE__)
#endif // _DEBUG

int main(int argc, char *argv[])
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
char *c = new char;
return EXIT_SUCCESS;
}


output is now:

Detected memory leaks!
Dumping objects ->
c:\documents and settings\gumpy\my documents\visual studio projects\blah\blah\main.cpp(11) : {42} client block at 0x00320FF0, subtype 0, 1 bytes long.
Data: < > CD
Object dump complete.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!