Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging memory leaks

Status
Not open for further replies.

gmgarrison

Programmer
Sep 26, 2000
11
US

Here is an example of the errors I'm trying to correct:

{3208} normal block at 0x00F452D0, 17 bytes long.
Data: <GGARRISON > 47 47 41 52 52 49 ...

This information is given after memory leaks on detected and the debugger dumps the objects. Can anyone give any general tips on resolving these leaks? Particularly, VC++ complains that various memory allocations are too large by a certain number of bytes. What is the likely culprit?? Does having the data and memory address of the allocation do anything for me after the program has exited? Finally, I can't figure out what the {3208} signifies... If anyone has any tips or suggestions, I'd appreciate it!!

Thanks,
Greg
 
Judging by the stuff in angle brackets, <GGARRISON >, I'd say that you're leaking a character buffer containing your name. So I would first look at the code where such a buffer is intended to be allocated and freed.

{3208} is some sort of request number. It appears to come from line the following line:

_RPT1(_CRT_WARN, &quot;{%ld} &quot;, pHead->lRequest);

On my system, at least, that's line 1984 of &quot;c:\program files\microsoft visual studio\vc98\crt\src\dbgheap.c&quot;.

As a general tip, I put the following lines at the top of all my .CPP files:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

That has the effect of giving me the file and line from which the memory was allocated. For instance, if I write this sloppy code on line 66 of &quot;MemoryTestDoc.cpp&quot;:

new int; // obvious memory leak

Then I might get the following trace:
Detected memory leaks!
Dumping objects ->
D:\MemoryTest\MemoryTestDoc.cpp(66) : {91} normal block at 0x00770030, 4 bytes long.
Data: < > CD CD CD CD
Object dump complete.

The down side of this is that I think it might only work with MFC projects. I'm really not sure.

Anyway, for more info, please try:

Also, there's a guy by the name of John Robbins who knows lots of stuff about debugging. You can find one of his articles on memory leaks at

His web site may be found at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top