TComInterface
calls Release()
on its internal interface when TComInterface
goes out of scope and gets destructed. You can also call the TComInterface::Unbind()
method if you want to manually Release()
the interface sooner. TComInterface
also calls Release()
on its current interface if you assign a new interface pointer (or other TComInterface
instance) via the =
assignment operator.
TComInterface
overrides the &
operator to return a pointer to its internal interface, so you have to make sure that TComInterface
is not holding an active interface before you call CoCreateInstance()
(or anything else that will copy a new interface into TComInterface
) or else the preview interface will be leaked and not released. TComInterface
's default constructor sets the internal interface to NULL, so you don't usually have to worry about that, unless you re-use the same TComInterface
variable multiple times, such as when using interface enumerators in a loop.