media session - handle leak RRS feed

  • Question

  • Hi,

    I'm using IMFMediaSession and IMFTopology to realize media capturing. Capturing works fine, but it seems there is a handle leak:

    When I create the MF stuff about 50 handles are created, when I clean it up, only about 10-20 handles are freed.

    How do I release the MF stuff in a clean way? Is there a possibility to check which handles (MF objects) are not cleanly release?

    br, alex

    Thursday, May 20, 2010 10:05 AM

All replies

  • Are you shutting down all objects with Shutdown methods (sources, sinks, media sessions) and calling MFShutdown?  Objects with Shutdown methods likely have circular references that will cause the object to persist in memory unless the Shutdown method is called.  Also, MFShutdown is a bit annoying because it performs the shutdown asynchronously but the application is not informed when it is finished.  If you take a measurement of the handle count right after calling MFShutdown, the MF platform may not have closed all handles yet -- waiting ~50ms or so should be enough for the platform to shutdown.  If you believe you have covered these bases but are still seeing handle leaks, let me know and I will see if I can reproduce it.
    Tuesday, May 25, 2010 11:01 PM
  • I call MFStartup resp. MFShutdown at application-start resp. application-end.

    While my application is running, the user has the possibility to start/stop recording multiple times. Each time the recording is started, a new IMFTopology is built using the user's configuration and deployed using a new IMFMediaSession. Each time the recording is stopped, the IMFMediaSession is stopped, closed and shut down. I shutdown the IMFMediaSources, the aggregated source if it was created and the IMFMediaSinks.

    I do not trace the handle count manually, but using the Performance Monitor. For each recording start about 70 handles are allocated, but at recording stop only about 40 handles are released.

    In the meantime I also removed any unnecessary references to MF objects that where held by my code, but without decreasing the leak. I also checked my code several times to verify that the received MF references are released using SAFE_RELEASE. Doing that I found some spots and could reduce the leak from 70 to about 30 - so it's very unlikely that I missed that many other spots. Is there a possibility to maintain the COM-references in a cleaner way since my code is managed C++ (w/o ATL).

    Wednesday, May 26, 2010 8:26 AM