Do I delete instance data of a com object in release or in destructor?
Release is supposed to, as the name says, release instance data. This is also the task of a destructor in c++. Now where should i release instance data? Which one is called first?
A COM object keeps track of how many times AddRef and Release have been called on it. This is called the RefCount.
When the RefCount drops to zero, it means no one is holding a reference to the object anymore, and it deletes itself.
You and your code never really know exactly what other elements of a program may be holding a reference to a COM object, so you should not explicitly delete the object.
Rather, you should call Release when you are done with it. When the last Release is called, the object will delete its own data.
Release is supposed to decrement the reference count. Only if the reference count reaches zero, the object is destroyed an the destructor called.