views:

775

answers:

3

I have a .NET application, which is using an open source C++ compression library for compressing images. We are accessing the C++ library via managed C++. I'm seeing heap corruption during compression. A call to _CrtIsValidHeapPointer is finding an error on a call to free() when cleaning up after compression.

My question is, are there tools such as Purify to help diagnosis this problem and what is causing the heap corruption when working in a combination of managed and unmanaged code? I do have the exception caught in the debugger, but it would be nice to have other tools to help find the solution to the problem.

A: 

Rational Purify for Windows supports .NET, so I guess that could be used?

Anders Sandvig
Last time I used Purify, if you're using managed code in your application, then it doesn't even try to track unmanaged memory and just shows you the size of the managed heap and when GCs occur.In an entirely unmanaged app, Purify is an absolute life saver!
Colin Desmond
+1  A: 

on *nix, there's a tool called valgrind that I use for dealing with memory issues, like memory leaks and memory corruption.

Misha M
A: 

In native code, if the corruption always occurs in the same place in memory, you can use a data breakpoint to break the debugger when that memory is changed. Unfortunately, you can not set a data breakpoint in the managed C++ environment, presumably because the GC could move the object in memory.

Not sure if this helps, but hopefully it leads you off in the right direction.

Nathan