- Apr 30, 2005
- 81
- 0
- 66
Hi,
I need some help with a memory leak between a C++ COM exe and a C# .NET dll. The .NET dll uses hand-crafted interface definitions ( see below ) to match those of the IDL in the COM exe ( uncertain if that is relevant but would be difficult to change at this point ).
Both Foo() and Bar() work in so far as the data gets marshaled between the two binaries but they both result leaks. The .NET dll invokes Bar() using Marshal.AllocCoTaskMem(), Marshal.Copy(), and Marshal.FreeCoTaskMem() to provide the IntPtr.
Additional testing has shown that the leak still occurs even if 0 bytes of data ( empty array, IntPtr.Zero ) are provided as parameters. Any ideas?
Sample interface defined in COM exe:
[ object
, uuid( xxx )
, pointer_default( unique )
]
interface ITest : IUnknown
{
HRESULT Foo( [ in ] ULONG size, [ in, size_is( size ) ] BYTE *pData );
HRESULT Bar( [ in ] ULONG size, [ in, size_is( size ) ] BYTE *pData );
};
Sample interface defined in .NET dll:
[ ComVisible( true ) ]
[ Guid( "xxx" ) ]
[ InterfaceType( ComInterfaceType.InterfaceIsIUnknown ) ]
public interface ITest
{
void Foo( UInt32 size, [ MarshalAs( UnmanagedType.LPArray, SizeParamIndex=0 ) ] Byte[] data );
void Bar( UInt32 size, IntPtr pData );
}
Cheers!
I need some help with a memory leak between a C++ COM exe and a C# .NET dll. The .NET dll uses hand-crafted interface definitions ( see below ) to match those of the IDL in the COM exe ( uncertain if that is relevant but would be difficult to change at this point ).
Both Foo() and Bar() work in so far as the data gets marshaled between the two binaries but they both result leaks. The .NET dll invokes Bar() using Marshal.AllocCoTaskMem(), Marshal.Copy(), and Marshal.FreeCoTaskMem() to provide the IntPtr.
Additional testing has shown that the leak still occurs even if 0 bytes of data ( empty array, IntPtr.Zero ) are provided as parameters. Any ideas?
Sample interface defined in COM exe:
[ object
, uuid( xxx )
, pointer_default( unique )
]
interface ITest : IUnknown
{
HRESULT Foo( [ in ] ULONG size, [ in, size_is( size ) ] BYTE *pData );
HRESULT Bar( [ in ] ULONG size, [ in, size_is( size ) ] BYTE *pData );
};
Sample interface defined in .NET dll:
[ ComVisible( true ) ]
[ Guid( "xxx" ) ]
[ InterfaceType( ComInterfaceType.InterfaceIsIUnknown ) ]
public interface ITest
{
void Foo( UInt32 size, [ MarshalAs( UnmanagedType.LPArray, SizeParamIndex=0 ) ] Byte[] data );
void Bar( UInt32 size, IntPtr pData );
}
Cheers!