title: COM Object Clean Up
body: <p>What is the difference between the two lines of code below:</p>
  
  <pre><code>CComPtr&lt; IInterface &gt; m_interface;
  
  IInterface* m_interface;
  </code></pre>
  
  <p>I know that CComPtr help eliminate memory leaks, but I am getting inconsistent results. When declaring the pointer with <code>CComPtr&lt; IInterface &gt; m_interface;</code>
  and using the interface in my C# code there are no errors, however using the Interface in VC++  I get an unhandled exception error, even if I comment out the instance creation of IInterface.</p>
  
  <p>I am pretty sure the problem is in here somewhere:</p>
  
  <pre><code>STDMETHODIMP CSomeClass::get_IClass(IClass** var)
  { 
        return m_class_var-&gt;QueryInterface(var);
  }
  STDMETHODIMP CSomeClass::putref_IClass(IClass* var)
  { 
       m_class_var = var;
       return S_OK;
  }
  </code></pre>
  
  <p>When I declare the interface pointer with: <code>IInterface* m_interface;</code> 
  I get a RPC_E_SERVERFAULT error when testing the Interface in C# and have to explicitly call GC.Collect() to avoid the error being thrown after instantiation of a few objects. When testing the Interface in VC++ the error is consistent however when it occurs is different. If I comment out the instance creation of IInterface the code runs fine, however when I try to create an instance I get same error as before, just a vague unhandled exception error. What am I doing wrong here? </p>