Releasing a com interface
-
Hi Experts, I am using third party com Dll interafces.But sometimes the interfaces return E_OUTOFMEMORY EXCEPTION.So tell me how to release com interface. Thanks
-
Hi Experts, I am using third party com Dll interafces.But sometimes the interfaces return E_OUTOFMEMORY EXCEPTION.So tell me how to release com interface. Thanks
The exact mechanism depends on how you're using it. If you're using #import or CComPtr<> smart pointers, then you release the interface by setting the pointer to NULL. If you aren't using smart pointers in this way, you have to call the Release() method. Note that if you copy a pointer without using AddRef() or QueryInterface(), the object may go away unexpectedly. Similarly, if you use AddRef() or QueryInterface() with no corresponding Release(), the object implementing the interface will not necessarily disappear when you expect it to..
Steve S Developer for hire
-
Hi Experts, I am using third party com Dll interafces.But sometimes the interfaces return E_OUTOFMEMORY EXCEPTION.So tell me how to release com interface. Thanks
What language are you coding in? In VB, just make sure you set all of the objects you create to Nothing as soon as you're done with them:
Set MyLibraryInterface = Nothing Set MyBusinessObject = Nothing
In many situations, you don't really need to do this unless you're creating a lot of objects that don't fall out of scope right away In C++, you just call ->Release() on your interface pointer.MyComObject* pMyComObject = NULL; (send the pointer into your class factory CreateInstance call here) (do your business logic here) pMyComObject->Release(); // All done
Hope this helps.