1

I am developing a 3D game for Windows Store. I have detected memory leaks in the game but I am not able to see the file name and line number of the memory leaks in the output while debugging. The following are the lines of code that I have included to detect memory leaks:

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

_CrtDumpMemoryLeaks();

The following is the output on debugging the application:

Detected memory leaks!
Dumping objects ->
{1686} normal block at 0x06FD72E8, 8 bytes long.
Data: <        > 08 F5 FE 03 00 00 00 00 
{1685} normal block at 0x03FEF500, 40 bytes long.
Data: <    x    r      > 20 E5 B4 01 78 EE FE 03 E8 72 FD 06 00 A9 03 04 
{1684} normal block at 0x0403A900, 64 bytes long.
Data: <W i n d o w s . > 57 00 69 00 6E 00 64 00 6F 00 77 00 73 00 2E 00 
{1676} normal block at 0x0406C858, 36 bytes long.
Data: <         K      > FF FF 00 00 FF EE 82 EE FF 4B 00 82 FF 00 00 FF 
{1658} normal block at 0x06FD7208, 8 bytes long.
Data: <        > 80 EE FE 03 00 00 00 00 
{1657} normal block at 0x03FEEE78, 40 bytes long.
Data: <         r   J  > 00 F5 FE 03 F8 F3 FE 03 08 72 FD 06 E0 4A F7 06

Whereas, according to Microsoft blogs, I should be getting the name of the file and line number when _CRTDBG_MAP_ALLOC is included in the code like the following:

Detected memory leaks!
Dumping objects ->
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18} 
normal block at 0x00780E80, 64 bytes long.
Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.

I am not getting the similar output (file name and line number) even after including _CRTDBG_MAP_ALLOC in the code. Please help me resolve this issue.

Thanks in advance!

Charles
  • 50,943
  • 13
  • 104
  • 142
  • Does this help? http://stackoverflow.com/questions/1567866/visual-studio-2008-c-memory-leak-detection-not-showing-file-method-location – doctorlove Jul 23 '13 at 08:21

1 Answers1

2

There are similar questions on SO

Does this work?

#ifdef _DEBUG
#define DEBUG_NEW_PLACEMENT (_NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_NEW_PLACEMENT
#endif

int* p = new DEBUG_NEW_PLACEMENT int(5);

Alternatively, if the memory allocation number (inside the curly braces) is always the same, you can set a break point using the number, e.g.

_CrtSetBreakAlloc(18);

Details here

Community
  • 1
  • 1
doctorlove
  • 18,872
  • 2
  • 46
  • 62