The crux if the issue is that CComPtr manages this to a large extent, maintaining its own reference and calling AddRef() when created and Release() when destroyed (using the RAII idiom (RAII - Wikipedia[^]). Whenever you hold a pointer to a COM object, generally wrap it in a CComPtr and C++ will correctly managed AddRef/Release for you.
Occasionally, you can use a pointer to the interface directly. For example, if a function you write receives an IMFMediaSession* as a parameter, and the only way you use the parameter is to directly call methods (using -> ), then you don't need to use AddRef/Release (be sure to check for null though).
The main consideration is lifetime of the reference. Always, for example, use CComPtr for:
Hope this helps.
- Members of a class or struct, where the sub-object will get destructed (hence Released) when the object is destroyed.
- In a method, when you invoke another function that may possibly copy the reference (if you're not sure - use CComPtr for safety.
The COM overview is here Component Object Model
Rules for managing reference counts are here: Reference Counts