It's not always followed directly like this, though that is pretty common.
COM objects are reference counted. When you initially create the object, you get a pointer to an IUnknown
. Then you obtain some other interface with QueryInterface
. Since you (usually) don't care about the IUnknown
interface anymore, you release that. When you release the other interface you obtained, the reference count will be 0 so the object can be destroyed. If you don't release the IUnknown
, however, the reference count will stay non-zero, so the object can't be destroyed.
The most obvious case where you would not immediately release the IUnknown
is when/if you need to get more than one other interface. In such a case, you'd get the IUnknown
, then the second and third interfaces before releasing the IUnknown
. There are at least potentially cases where you might not know the third (or subsequent) interfaces right after you created the object either, so you might need to retain access to the IUnknown
for some arbitrary length of time before releasing it.