Virtual Developer Workshop: Containerized Development with Docker

I recently came across something that I found to be a major improvement in my ability to program in MS Developer Studio version 5. It concerns memory leaks. When running the Debugger, if you have the Dump function on, you get a list of objects that did not get deallocated. These are defined as 'Memory Leaks'. If we allocate memory for a character array in a function:
void MyFunction(void)
	char * MyCharArray = new char[10];
	//delete [ ]MyCharArray;

but we don't free it, running the program will produce the message:
Detected memory leaks!
Dumping objects ->
C:\vcpp32\myproject\test.cpp(62) : {39} normal block at 0x00780DF0, 10 bytes
 Data: <          > CD CD CD CD CD CD CD CD CD CD
Object dump complete.

Now in this case, it gave us the CPP file and line number, but often it does not. One way to find the leak would be to put a breakpoint in memory at the memory address used by the allocation (assuming it's constant).

But there's a better way!

The number in the curly brackets, is an allocation number. Each allocation receives a serial number. When you get a leak, you can use this number to automatically place a breakpoint at the point in the program where the allocation is being made. To do this, you can do one of two things.

1. Add a call to the function _CrtSetBreakAlloc(), giving it the number in the curly brackets.

2. In the debugger, set the value of the variable _crtBreakAlloc to that number.

You want to do this as early in the program as possible. The effect of doing that is a breakpoint on the line of the allocation of the 'new' function. You then use the call stack to find the exact place in the program that called the allocation. (See MSDN article Q151585 for more information)


  • mem shared between apps?

    Posted by Legacy on 02/13/2004 08:00am

    Originally posted by: Phil Beck

    I have three applications running on an NT4 machine. They share several dlls that were written in house.

    If I run any of them under the MSVC++ 5 debugger, then I get no reported memory leaks. However, all three applications appear to slowly increase in the amount of memory they use. The only thing that tells me this is the memory column in the processes page of task manager.

    If I then shut one of the apps down, the other two apps suddenly drop down to their original memory usage.

    I am quite experienced in using the C Runtime debug heap and _CrtSetAllocHook().

    I'm not too sure where the MFC version in MSVC++5 stands on its abililty to dump memory leaks.


  • "_crtBreakAlloc" undefined

    Posted by Legacy on 03/04/2003 08:00am

    Originally posted by: pat


    I tried setting _CrtSetBreakAlloc() giving it the number in the curly brackets I get in the debug window.

    I run my app in debug-mode and wanted to access "_crtBreakAlloc" in the Watch-Window, but it was undefined ((CXXX0017: Error:: symbol "_crtBreakAlloc" not found))!
    What's my mistake?

    Thanks for your help

    • "_crtBreakAlloc" undefined reply

      Posted by happy_red on 07/21/2004 11:40am

      If you are linking against the multithreaded runtime dll. Try puting "{,,msvcrtd.dll}_crtBreakAlloc" in your watch window.

  • Find who and not were is the memory leak!!!

    Posted by Legacy on 12/16/2002 08:00am

    Originally posted by: PaoloB

    This tecnique is only valid for memory leak generated from class with vtable.

    So, if you have this:
    normal block at 0x048B80C0, 16 bytes long.
    Data: < $ > 18 DA 24 01 00 00 00 00 00 00 00 00 00 00 00 00

    insert in your application a code for ask
    a string and

    CString cl = "0124DA18"; // usualy ask like inputbox :-)
    char * foo = " ";
    char * p;
    void * ptr = (void *)strtoul(cl, &p, 16);

    debug ptr to see vtable description:

    ptr 0x0124da18 const ClassUnDeleted::`vftable'


  • How to detect memory leaks !!!

    Posted by Legacy on 11/07/2002 08:00am

    Originally posted by: Narayanan N

    Has anyone used the umdhtools from Microsoft for dectecting the memory leaks in Windows XP??


  • See Knowledge Base article Q151585

    Posted by Legacy on 07/03/2002 07:00am

    Originally posted by: Jonathan

  • Can any one help me to find memory leak

    Posted by Legacy on 06/27/2002 07:00am

    Originally posted by: shashi

    How to detect memory leaks if some thing like below appears in your debug window after completion of debugging.
    Detected memory leaks!
    Dumping objects ->
    {318} normal block at 0x02077700, 60 bytes long.
    Data: <8 > 38 87 0F 10 CD CD CD CD 00 CD CD CD CD CD CD CD
    Object dump complete.
    The thread 0x124 has exited with code 0 (0x0).
    The program 'D:\Tester\Debug\Tester.exe' has exited with code 0 (0x0).


  • Memory Leaks in Normal blocks

    Posted by Legacy on 04/05/2002 08:00am

    Originally posted by: Farooq Mulla

    I am stuck with a memory leak where memory leaks occur in steps of 4kb which makes my mem size above 7MB ....

    I checked out the dumping objects ---> created after debugging to get the memory leaks which showed up a couple of pointers i hadnt released which i rectified ,but even then it shows memory leak in plex.cpp (which is a part of the VC++) the message reads something like this

    plex.cpp (line 31) <memory location> 164 bytes in Normal blocks
    (this line appears for large no of times,at different mem locations which amounts to quite a big mem leak 164bytes*n)

    wheras the free blocks occupies 0 bytes & dbg blocks occupies 100 bytes

    how do i remove this memory attached in normal blocks ..

    whats this concept of normal blocks,dbg blocks & free blocks...

    could u plz give me a hint to this.

  • Skip Memory Leaks of Global variables ...

    Posted by Legacy on 03/21/2002 08:00am

    Originally posted by: jesvh

    Hello, all:

    If a c run time program (win32 console application) with
    several const global c++ class instances (not use MFC) .

    How do I skip memory-leak messages of them ?
    _CrtDumpMemoryLeaks only works before program exit. but
    global class instance destructors work after that .....


    class AA
    char *pp;

    ~AA() { free(pp); };

    const AA a-obj;

    void main()



    pp will be showed as memory leak .... but it doesn't.
    Is there any method to skip it ?

  • Need help in writing memory dump to a file

    Posted by Legacy on 11/22/2001 08:00am

    Originally posted by: Nagaraj Rao

    In VC++ under debug windows, I can use memory window to see contents of particular memory location. Is there a way to write this data( which is suppose to be in HEX) into a file by specifying address ranges ? Does Visual studio has some options ?
    Ex: If I want to write data contents from memory location to 0x1000 to 0x2000, how do do it ?


    Nagaraj Rao

  • Testing tools for memory leaks in complex applications

    Posted by Legacy on 08/05/1999 07:00am

    Originally posted by: Abdul Hafeez

    Hi friends,

    The techniques for tracking memory leaks are excellent, but in a practical software development we can't be sure if all the control paths of execution are free of memory leaks.

    I have a suggesion regarding testing of memory leaks. There are software likes BoundsChecker , Verify etc., which are efficient in testing the memory leaks. Once you install softwares they will get integrated with the Visual Studio environment and are easy to test the applications.

    Here in we can get the exact details with analysis of all the memory leaks.

    Abdul Hafeez

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date