Posts

Showing posts with the label Tools

memory leak detection notes (continuously updating)

Memory leak problem is very common, below is some my previous working notes: BoundsCheck BoundsCheck does not work well with mixed codes. Since my latest projects are almost all mixed, so, seldom used in my daily work. Visual studio Enable memory leak reporting There are two ways to enable memory leak check in VC, one is to define DEBUG_NEW macro, another is as below: 1: #define _CRTDBG_MAP_ALLOC 2: #include<stdlib.h> 3: #include<crtdbg.h> Then calling _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); when initializing your app. With the above changes, visual studio can dump memory block leak when quitting or between two snapshot via Windows API. For instance: c:\program files(x86)\microsoft visual studio\vc98\include\crtdbg.h(552) : {43} normal block at 0x00441C20, 40 bytes long. Data: < C > 08 02 43 00 16 00 00 00 00 00 00 00 00 00 00 00 Output mode The above output is one sample of block leak, in which, {43} is the heap block a...

BoundsCheck not working with mixed codes

Previously, we have tried to use BoundsChecker to test our mixed programs. But it does not support managed code and also cause huge memory usage during running, Recently, I tried "Application Verifier", a great tool distributed by Microsoft, can be used alone or together with Visual studio team version, and it seems to be acceptable. The below code can be found immediately: 1: int * p = new int [10]; 2: p[11]=1; // this cannot be detected, since the heap block has additional 8-bytes suffix, it seems that AppVerif does not check with this 3: p[100] = 1; // this can be detected immediately, since AppVerif generates memory fence after the heap block. After running with Application Verifier, the memory usage is also acceptable. Another thing related to this is that AppVerif can only work with native codes. As for the mixed code, msdn does not say clearly. Two potential results can be: 1: AppVerif can only check native memory, ignore managed objects. 2: AppV...

Make NCover work on 64-bit machine

It seems that the free NCover does not work well on 64-bit machine. One solution is to force your testing targets and ncover binaries to run as 32-bit mode, even they are managed binaries compiled with AnyCPU configuration. The steps are as below: 1: change the PE flag in NCover.Console.exe: corflags ncover.console.exe /32bit+ corflags is available in visual studio's command prompt 2: create a config file as below 1: <? xml version ="1.0" encoding ="utf-8" ? > 2: < ProfilerSettings > 3: <!-- The unit-test loading program, should also be 32-bit, either change pe flag or rename to another one: nunit-console-x86.exe --> 4: < CommandLineExe > C:\Program Files (x86)\NUnit 2.5.5\bin\net-2.0\nunit-console.exe </ CommandLineExe > 5: < CommandLineArgs > Test.dll </ CommandLineArgs > 6: <!-- The target assembly to be loaded --> 7: < WorkingDirectory > D:\Test\bin\Release </ ...