Microsoft KB Archive/814795

= BUG: MFC does not display the file name for internal memory leaks when you debug an application =

Article ID: 814795

Article Last Modified on 5/31/2007

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-





SYMPTOMS
When you try to debug an application that uses Microsoft Foundation Class (MFC), you may not receive the information about the origin of the internal memory leaks in MFC. The file name and the line number information about the memory leaks is not displayed in the Output window of the Microsoft Visual Studio .NET IDE.



CAUSE
This behavior occurs because the wrapper files that are created in the intermediate folder are deleted when you clean the solution.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
In the debug version of the MFC7 runtime that is included with Visual Studio .NET, the _CRTDBG_MAP_ALLOC preprocessor symbol is not defined. Therefore, whenever the implementation of MFC calls a C run-time library (CRT) memory allocation function, such as the realloc function, the function is not redefined to the debug version that keeps track of the information about the source file and the line number.

Steps to reproduce the behavior
 Start Visual Studio .NET. On the File menu, point to New, and then click Project. The New Project dialog box appears. Under Project Types, click Visual C++ Projects. Under Templates, click Win32 Project. In the Location box, type C:\Samples\814795 . In the Name box, type TestApplication, and then click OK. The Win32 Application Wizard - Test Application dialog box appears.</li> On the Welcome to the Win32 Application Wizard page, click Application Settings. The Application Settings page appears.</li> Under Application type, click Console application.</li> Under Add support for, click to select the MFC check box, and then click Finish.</li>  In the code view of the TestApplication.cpp file, add the following code to the else block of the _tmain function: CString* px = new CString; On the Build menu, click Build Solution.</li> On the Debug menu, click Start. You see the lines that are similar to the following in the Output window:
 * px += &quot;Hello World&quot;; </li>

Detected memory leaks!

Dumping objects ->

{120} normal block at 0x00365C90, 28 bytes long.

Data: < 2| > D8 9C 32 7C 0B 00 00 00 0B 00 00 00 01 00 00 00

c:\samples\814795\TestApplication\TestApplication.cpp(30) : {119} normal block at 0x00365C50, 4 bytes long.

Data: < \6 > A0 5C 36 00

Object dump complete.

You may see two memory leaks. The first memory leak is the internal memory leak from MFC, and the second is the memory leak from the user-defined object. The file name and the line number are displayed for the memory leak from the user-defined object, but the file name and the line number are not displayed for the internal memory leak from MFC.</li></ol>

<div class="references_section">