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)?
Make sure to call free() when you use malloc() or calloc() . Don't reassign pointer which points to allocated memory location without free() ing it first i.e. don't lose the reference.
Memory leak occurs when programmers create a memory in heap and forget to delete it. The consequences of memory leak is that it reduces the performance of the computer by reducing the amount of available memory.
There are two types of memory leaks: apparent and subtle. An apparent memory leak is a chunk of heap memory that's never referred from active memory, a subtle leak is memory that is still referred to but shouldn't be, i.e. a hash or dynamic array holds the references.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With