Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put the destructor code for an ATL COM object?

Where does the destructor code for things I have defined in an ATL COM object belong?

Should it go in ~MyComClass() or in MyComClass::FinalRelease()?

like image 808
Sideshow Bob Avatar asked Feb 16 '12 15:02

Sideshow Bob


1 Answers

As long as FinalRelease is in question, I assume your question is related to ATL.

In most cases you can clean things up in either of the two. FinalRelease will be called immediately before the actual destructor. The important difference is that if you aggregate other objects, FinalRelease gives you a chance to clean the references and release dependencies before actual destructor of top level COM object class (esp. CComObject) starts working.

That is, you clean things up in two steps, first references to aggregated objects in FinalRelease and then other things in either FinalRelease or destructor.

like image 95
Roman R. Avatar answered Sep 21 '22 00:09

Roman R.