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

Where does the destructor code for the things that I defined in the ATL COM object belong to?

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

+4
source share
2 answers

While the question is FinalRelease , I assume your question is related to ATL.

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

That is, you clear things in two stages, first refer to aggregated objects in FinalRelease , and then to other things in FinalRelease or the destructor.

+10
source

This is a general approach:

 MyComClass::~MyComClass() { // Cleanup object resources in here. } ULONG __stdcall MyComClass::Release() { ref_count_--; if (0 == ref_count_) { delete this; return 0; } return ref_count_; } 

EDIT: FinalRelease() seems to be related to ATL, which I am not familiar with.

+1
source

Source: https://habr.com/ru/post/1396869/


All Articles