views:

27

answers:

1

Hi,

Here is a question about IMFActivate::ActivateObject and IMFActivate::ShutdownObject in Media Foundation.

According to MSDN, the component that calls ActivateObject is responsible for calling ShutdownObject.

But there are two examples not following this rule:

http://msdn.microsoft.com/en-us/library/dd388503%28VS.85%29.aspx

and

http://msdn.microsoft.com/en-us/library/dd317912%28VS.85%29.aspx

In these two examples, they call ActivateObject and then release IMFActivate interface without calling ShutdownObject method.

This is going to lead to memory leaking, right? Or there is another way to release the resource occupied by the object?

(Can I use IMFMediaSource::Shutdown to release the object instead of using IMFActivate::ShutdownObject)

Thanks in advance.

A: 

You're right that you're supposed to call IMFActivate::ShutdownObject when you're done using the object you activated. However, notice that the sample in question is instantiating an IMFMediaSource to be returned in an out param.

HRESULT CreateVideoDeviceSource(IMFMediaSource **ppSource)

If CreateVideoDeviceSource were to do a ShutdownObject on the IMFMediaSource it instantiated and then hand it back to you, it would be in a shut-down state and therefore probably unusable.

To answer your question about what you're supposed to do about this, you can probably get away with a pMyMediaSource->Shutdown() after you're all done using it.

More info: IMFActivate's other use in Media Foundation is for allowing an MF object to be instantiated in a different process (useful because the MF Media Session will play DRM-protected content in a separate process); in that case, the MF Media Session will indeed call IMFActivate::ShutdownObject on any IMFActivates you gave it.