• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Tracing memory leaks

## Recommended Posts

The debugger keeps complaining about a memroy leak and i cant seem to find it. Heres what i get from the debugger: Detected memory leaks! Dumping objects -> {128} normal block at 0x006B7BC8, 3496 bytes long. Data: < > 00 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 {84} normal block at 0x006B6DF4, 3496 bytes long. Data: < > 00 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 Object dump complete. I was wondering if i could use this to determine where the leak occurs. Any suggustions? tia, - llvllatrix

##### Share on other sites
Use _CrtSetBreakAlloc( n ); to break at alocation n. (in your case 128 )

You should never let your fears become the boundaries of your dreams.

##### Share on other sites
I''m assuming you''re using VC++.

The number in the {} is the allocation number of the block of memory that is being leaked. Run your program and note what value is given in the leak dump. Put a breakpoint somewhere at the beginning of your program (i.e. line 1 of the main fuinction) and run the program again. When it breaks, put _crtBreakAlloc (if you''re statically linking the runtime library) or {,,msvcr71d.dll}_crtBreakAlloc (if you''re using the multithreaded dll option - change the dll option to whatever version you''re using)
in the watch window and change its value (it defaults to -1) to the number. Then continue the run. The program should break on the line that allocates the memory being leaked. You might need to move back on the stack a bit to find the code you wrote that is causing the leak but it should be obvious what is causing the problem.

If the allocation number is never the same, then it is a bit harder to track down. There is a way of changing the way the new operator is used to include the line number and file when an allocation is made, so that you can click on the memory leak dump and go straight to the leak, but I haven''t done this myself.

Good luck

##### Share on other sites
thx guys, found it

##### Share on other sites
Super handy tip: if you''re using MFC, add the following to your code (in your stdafx.h is a good spot)

#ifdef _DEBUG// provides file/line numbers in MSVC''s mem leak output   #define new DEBUG_NEW#endif

##### Share on other sites
There are also excellent memory managers like mmgr by Paul Nettle
http://www.fluidstudios.com/pub/FluidStudios/MemoryManagers/Fluid_Studios_Memory_Manager.zip

• ### Forum Statistics

• Total Topics
627733
• Total Posts
2978839

• 10
• 9
• 21
• 14
• 12