|After more than 8 hours trying to fix up a memory leak I need some help :/
I have a ATL COM component, with the following interface:
STDMETHODIMP CDCSClient::CallService( VARIANT *p1 )
Inside the method I do the following:
VariantClear( p );
VariantInit( p );
p->vt = VT_BSTR | VT_BYREF;
BSTR *pBSTR = new BSTR;
*pBSTR = SysAllocString( L"abc" );
p->pbstrVal = pBSTR;
And my client in VB is like this:
For i = 1 To 1000
Dim myInt As Integer
myInt = 3
ret = client.CallService(myInt)
As far as I know the COM engine is creating a VARIANT from my integer (which is received as VT_BYREF | VT_I2), and I change it to VT_BSTR.
The VB loop causes a huge memory leak.
Am I doing something wrong ? How the COM engine handles the new VARIANT/BSTR deallocation ?
Thanks for any help.