locked
Why do these two examples call IMFActivate::ActivateObject but not IMFActivate::ShutdownObject? RRS feed

  • Question

  • 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 don't 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 instead of using IMFActivate::ShutdownObject)


    Thanks in advance.
    • Edited by The March Hare Sunday, September 13, 2009 3:25 PM clarify title and add links
    Sunday, September 13, 2009 6:09 AM

Answers

  • So the rule is: Whoever calls ActivateObject is responsible for shutting down the created object.

    To shut down the object, you can either call IMFActivate::ShutdownObject, or call the appropriate shutdown method on the object itself (but this varies by object type). However, there is no need to do both. So in the your example, the call to pSource->Shutdown() is not needed if you call ShutdownObject, and vice versa.

    An activation object should not shut down the object in its destructor. That means it is safe to release the IMFActivate pointer while the object is alive, but it also means you must shut down the object explicitly.

    Hope this helps - I'll try to clarify this issue in the IMFActivate documentation.



    - Mike




    Mike Wasson (SDK Documentation)
    • Marked as answer by optimaluu Friday, September 18, 2009 1:38 AM
    Thursday, September 17, 2009 4:40 AM

All replies

  • My guess is that the destructor takes care of the ShutdownObject call for you.  As in my previous response, I have asked a contact on the MF docs team for clarification since I can't check the Win 7 source code yet since it is not on Code Center Premium at this time.
    Please use Vote As Helpful (green up arrow at top-left of posts) and Mark As Answer where appropriate.
    My dshow site is http://tmhare.mvps.org.
    Sunday, September 13, 2009 3:55 PM
  • I think this is not the job of destructor. Because, if the destructor takes care of the ShutdownObject call, why the document says we have to call it after we are done with the obejct?

    (but, I do think this is a good idea if the destructor can take care of the ShutdownObject call. There are lots of post-process in Media Foundation to do)

    Thanks for your reply, and if there is an answer from MF docs team, please tell us.
    Monday, September 14, 2009 1:10 AM
  • It would be odd if it is done in the destructor and the docs don't make that clear.  It's certainly a good question to ask.  I will let you know if I hear back.
    Please use Vote As Helpful (green up arrow at top-left of posts) and Mark As Answer where appropriate.
    My dshow site is http://tmhare.mvps.org.
    Monday, September 14, 2009 3:39 AM
  • This question really haunts me. So I think I should highlight it again.

    When I am writing the following code, I kinda fell confused.

        // Get the media source object by using ActivateObject
        IMFMediaSource *pSource = NULL;                // Media source for the first video capture device
        if (FAILED(ppDevices[i]->ActivateObject(IID_PPV_ARGS(&pSource))))
        {
        // [someting]
        }


        // [use IMFMediaSource interface]


        // call IMFActivate::shutdownObject
        ppDevices[i]->ShutdownObject();

        // IMFMediaSource has to be shutdown, but I have already called IMFActivate::shutdownObject
        // Do I have to call IMFMediaSource::Shutdown again ?????????
        if (pSource)
        {
            pSource->Shutdown();
            pSource->Release();
            pSource = NULL;
        }


    Are IMFMediaSource::Shutdown and IMFActivate::ShutdownObject doing the same thing internally?
    Wednesday, September 16, 2009 1:02 AM
  • Mike is looking into this issue.  Hopefully, he will have an update for us later this week.
    Please use Vote As Helpful (green up arrow at top-left of posts) and Mark As Answer where appropriate.
    My dshow site is http://tmhare.mvps.org.
    Wednesday, September 16, 2009 1:22 AM
  • So the rule is: Whoever calls ActivateObject is responsible for shutting down the created object.

    To shut down the object, you can either call IMFActivate::ShutdownObject, or call the appropriate shutdown method on the object itself (but this varies by object type). However, there is no need to do both. So in the your example, the call to pSource->Shutdown() is not needed if you call ShutdownObject, and vice versa.

    An activation object should not shut down the object in its destructor. That means it is safe to release the IMFActivate pointer while the object is alive, but it also means you must shut down the object explicitly.

    Hope this helps - I'll try to clarify this issue in the IMFActivate documentation.



    - Mike




    Mike Wasson (SDK Documentation)
    • Marked as answer by optimaluu Friday, September 18, 2009 1:38 AM
    Thursday, September 17, 2009 4:40 AM
  • Thanks for your answer,

    this really helps. :D
    Friday, September 18, 2009 1:40 AM