0

I have an out of process COM server which has the following method:
STDMETHODIMP CMyCom::process(/[out]/BSTR* pResponse);
In this method I allocate memory for the pResponse attribute as follows:
*pResponse = ::SysAllocString("Some string");

My question is, when the method returns, who takes the responsibility for freeing the memory allocated for this BSTR? Is it the COM subsystem?

Paws
  • 189
  • 2
  • 8
  • Likely a duplicate of [Responsibility for memory deallocation in COM Interop](http://stackoverflow.com/q/18679659/1768303). – noseratio Sep 12 '13 at 10:14
  • [Allocating and Releasing Memory for a BSTR](http://msdn.microsoft.com/en-us/library/xda6xzx7%28v=vs.90%29.aspx) – Roman R. Sep 12 '13 at 13:04

1 Answers1

1
   STDMETHODIMP CMyCom::process(/*[out]*/BSTR* pResponse); 

It must be attributed with [out, retval] to be COM Automation compatible. The Automation contract demands that the caller deallocates it after using the string. Any automation client gets this right.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • What if the client is a Java class which is calling the COM server using jInterop? In such a case, how will the memory be freed? – Paws Sep 16 '13 at 05:20