Memory leak detection for mixed mode projects: managed, unmanaged and native
I have a Visual Studio 2010 solution that contains C# (managed), C++/CLI (unmanaged) and pure C++ (native) projects. I would like to perform memory leak detection across all 3 projects or at least around the native code:
I've tried using Intel Inspector XE 2011, but it's simply too slow... doing a simple thing like merely initializing my system and takes so long that I haven't even seen it complete yet. When I run my system without IXE 2011, it takes me no more than 10-15 seconds to initialize my system, while with IXE we've let it run for hours and it doesn't get past initialization. I've attempted to exclude certain libraries from being profiled, but it had absolutely no effect.
I've tried using the Visual Leak Detector, but after completing the run it said that it couldn't find any memory leaks. I was suspicious about that result so I intentionally placed a piece of code in a frequently run function to ensure that there is a memory leak:
int* memoryLeak = new int;
I ran with VLD again, but it spit out the same message. I'm considering overriding the new
/ delete
operators or even just the malloc
/ free
, but I wanted to make sure that I've exhausted all other options before I delve into doing that.
What can I do to profile the memory usage of my native C++ library with Visual Studio 2010? Are there any other tools or techniques that might work (even if they don't integrate with VS2010)?
In .NET even if you use managed objects there may be something that never get disposed (check some examples here: Memory Leak in C#).
About the native part, you may use two different approaches:
use a different memory profiler software, many listed here: Is there a good Valgrind substitute for Windows?
change your sources to use debug malloc/new and to print where in the code the allocations are done: http://www.flipcode.com/archives/Detecting_Memory_Leaks.shtml
Make unit tests which will test the units for memory leaks: http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx
Get the first memory state before allocating your object and the second after release it. Compare your memory states after.
Also you can try to use other profilers like valgrind, devpartner.
链接地址: http://www.djcxy.com/p/9788.html上一篇: 检查一个程序是否存在于bash中