Boost logo

Boost Users :

From: KLINIK Markus SDI2-G (AREVA NP GmbH) (Markus.Klinik_at_[hidden])
Date: 2007-03-26 04:25:36


> I am trying to get the --detect_memory_leak=1 option to detect a
> memory leak in my code.

Hi!

In MSVC 7.0 the memory leak detection is somewhat primitive (I don't
know about MSVC 8). I'm using Boost.Test together with mpatrol and it
works great! Here is the output of a test run:

<mpatrol_output>
top 4 unfreed memory entries in leak table:

       bytes count location
    -------- ------ --------
         400 1 d:\[snip]\unittests\test_config.cpp line 10
          84 1 d:\[snip]\tcpstream\src\myenv.cc line 145
          24 1 c:\src\boost_1_33_1\libs\thread\src\mutex.inl line
55
           8 1 c:\src\boost_1_33_1\libs\thread\src\tss_hooks.cpp
line 29
         516 4 total
</mpatrol_output>

NB. The first memory leak is intentional, the second is a resource leak
from cppadvio.
It also detects the already discussed resource leaks in Boost.Treads :)

I needed some try-and-error to find the correct versions of mpatrol,
Boost.Test and the windows runtime library, but now that it works, it is
incredibly useful. (/MDd, mpatrolmt.dll,
libboost_unit_test_framework-vc7-mt-gd.lib)

Just for comparison, here is the output of the MSVC 7.0 memory leak
detection of the same code:

<msvc_output>
Detected memory leaks!
Dumping objects ->
{11225} normal block at 0x00F3AA60, 24 bytes long.
 Data: < > 18 EE 14 00 FF FF FF FF 00 00 00 00 00 00 00
00
{11224} normal block at 0x00F3BBB0, 8 bytes long.
 Data: <` > 60 AA F3 00 01 CD CD CD
{201} normal block at 0x00F35F90, 400 bytes long.
 Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
CD
{147} normal block at 0x00F35880, 84 bytes long.
 Data: < =b > 10 3D 62 00 00 00 00 00 00 00 00 00 FF FF FF
FF
Object dump complete.
</msvc_output>

Best regards
Markus Klinik


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net