Basic COM  «Prev 

IUnknown reference counting

Who creates and destroys a COM object?

In the Release code in the lesson, a call to delete is made when the reference count goes to 0. The COM object actually deletes itself. But who creates it? Who calls the new CMyComObject?
One thing to keep in mind is that this is COM, not C++. The client does not call new to create a COM object. Instead, the client calls COM API functions to get an interface pointer to a class factory. The client asks the class factory to create an instance of the COM object it knows how to create. In response, the class factory code within the server creates a new C++ class that implements the COM object.