Re: Interpreting Visual C++ Object Dump.




> Hi, I have a MFC program created in Visual Studio 6.0. I noticed the
> following message if I manually exiting the program while running from
> the debugger in the "debug tab":
>
> ========================================================================
> The thread 0x944 has exited with code 0 (0x0).
> Detected memory leaks!
> Dumping objects ->
> {54} normal block at 0x020227F8, 928 bytes long.
> Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
> CD
> ...
> I have little in interpretting object dump in this environment. Some of
> the questions that I have:
>
> 1). Do I need to enable some setting neither in the source code or in
> some menu of visual studio to even get this object dump message?
>

In MFC projects everything is already set up to enable memory leak detection.
In non-MFC projects you have to enable it manually, with the help
of some macros and _CrtSetDbgFlag function (for more information,
see the links below; MFC's approach can be used as a good sample).

> 2). Any recommendations of a good resource where I can learn about
> object dump messages/memory leak detection methods for visual studio?
>

http://www.microsoft.com/msj/1097/bugslayer.aspx
http://msdn.microsoft.com/library/en-us/vccore98/html/_core_solving_buffer_overwrites_and_memory_leaks.asp
http://groups.google.com/group/microsoft.public.vc.mfc/browse_frm/thread/73493ddec165a5cb
http://www.codeproject.com/tools/leakfinder.asp

> 3). Since I get this message when I exit the program and the fact I can
> run the program for days without crashing, does that mean the memory
> leak as described in the message only occur WHEN the program exits?
>

You can get much better statistics about memory usage and possible
memory/resource leaks with Performance Monitor (see Administrative Tools | Performance).
Monitor at least the following counters for your Process object and see how
they change while the application is running:
- Private Bytes
- Virtual Bytes
- Handle Count
- Thread Count

> 4). Any thoughts as to what the memory leak can come from? I am pretty
> good at initializing variables and when I can avoid do not use the new
> operator or the malloc function...The data being dumped in above seems
> to be alot of New Page and Carriage Returns....any thoughts on
> that?>

'CD' is the fill pattern used for uninitialized data in heap blocks allocated
from CRT library heap. It means that the leaked blocks are not initialized.

> .... and what does the "{number }" mean?

This is the "allocation request number", the serial number of the allocation
that was leaked. If the allocation numbers of the leaked blocks are persistent
(the same) between debugging sessions, you can set a breakpoint at the given
allocation number so that the debugger will break at the moment when the
problematic block is being allocated, so that you can see who is allocating it.

http://msdn.microsoft.com/library/en-us/vccore98/html/_core_tracking_heap_allocation_requests.asp

But in general, it is better to use a tool that can show you the call stacks
of the leaked allocations, e.g. LeakFinder (see the link above).

Regards,
Oleg
[VC++ MVP]






.



Relevant Pages

  • mem leaks in dcmqrscp
    ... memory leak reporting tools, such as Purify, to ... Distribution of leaked blocks ... Allocation location ...
    (comp.protocols.dicom)
  • Re: [PATCH 1/2] slub: fix leakage
    ... Fix the memory leak that may occur when we attempt to reuse a cpu_slab ... situation we may overwrite the per cpu freelist pointer loosing objects. ... This only occurs if we find that the concurrently allocated slab fits ... our allocation needs. ...
    (Linux-Kernel)
  • Re: Fortran and .NET (C#)
    ... >> pointers (both in C and in Fortran) ... >> are subject to memory leak problems. ... > Both Fortran pointers and allocatable arrays allow dynamic allocation. ...
    (comp.lang.fortran)
  • Re: ZFS committed to the FreeBSD base.
    ... I don't see any evidence of a memory leak during the several days of testing leading up to the panic. ... How many days it took to happen would vary with the size of the kernel map, but no evidence of a leak prior to the crash. ... Also, the same server code, works fine for months on FreeBSD4 and OpenBSD3.9. ... mallocis actually implemented using two different back-ends: UMA-managed fixed size memory buckets for small allocations, and direct page allocation for large allocations. ...
    (freebsd-current)
  • Re: examine memory leak allocations
    ... You could make a base class that keeps trak of self instances in a internal ... linked-list (if your application is multithreaded you better protect the ... > the allocation represents? ... > just like visual studio does, except with the addition of info such as ...
    (microsoft.public.win32.programmer.kernel)