Many of the code examples in this documentation use the following function to release COM interface pointers.

template <class T> void SafeRelease(T **ppT)
    if (*ppT)
        *ppT = NULL;

Note  This function is not defined in an SDK header. To use this function, you must define it in your own code.

This function releases the pointer ppT and sets it equal to NULL.

Another option is to use a smart pointer class, such as CComPtr, which is defined in the Active Template Library (ATL).

Related topics

About Media Foundation