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



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

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 "Applies to" 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

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual C++ Projects.
  4. Under Templates, click Win32 Project.
  5. In the Location box, type C:\Samples\814795.
  6. In the Name box, type TestApplication, and then click OK. The Win32 Application Wizard - Test Application dialog box appears.
  7. On the Welcome to the Win32 Application Wizard page, click Application Settings. The Application Settings page appears.
  8. Under Application type, click Console application.
  9. Under Add support for, click to select the MFC check box, and then click Finish.
  10. 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;
    *px += "Hello World";
  11. On the Build menu, click Build Solution.
  12. On the Debug menu, click Start. You see the lines that are similar to the following in the Output window: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.

REFERENCES

For more information about the _CRTDBG_MAP_ALLOC preprocessor symbol, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:1/12/2006
Keywords:kbMemory kbtshoot kbDebug kbBug KB814795 kbAudDeveloper