Re: Windows Media Player Memory Leak

From: Jim Travis [ms] (jtravis_at_online.microsoft.com)
Date: 04/28/04


Date: Wed, 28 Apr 2004 14:30:50 -0700

Martin, the development team has responded by saying that you should not
QueryInterface from the Player for interfaces that are designed to be
accessed using property accessor methods. Instead of this:

// QueryInterface for Settings interface
 hr = pWP->QueryInterface(IID_IWMPSettings, (void **)&pWPSet);

You should do this:

// Retrieve the Setting interface
hr = pWP->get_settings(&pWPSet);

Same for IWMPControls. You can QI pWPSet if you, for example, need to get a
pointer for IWMPSettings2. You can QI IWMPPlayer for IWMPPlayer4.

Hope that helps.

-- 
Jim Travis
Microsoft Corp.
Windows Media Player SDK
Download:
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/winmedia.asp
Latest docs on MSDN:
http://msdn.microsoft.com/library/en-us/wmplay/mmp_sdk/default.asp?frame=true
Please do not send email directly to this alias as this alias is for
newsgroup purposes only. This posting is provided "AS IS" with no
warranties, and confers no rights. You assume all risk for your use. © 2004
Microsoft Corporation. All rights reserved.
"Jim Travis [ms]" <jtravis@online.microsoft.com> wrote in message
news:OVHPenuKEHA.2100@TK2MSFTNGP10.phx.gbl...
> Martin, thanks for the information. I've forwarded it on to the
development
> team.
>
>
> -- 
> Jim Travis
> Microsoft Corp.
> Windows Media Player SDK
>
> Download:
>
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/winmedia.asp
>
> Latest online:
>
http://msdn.microsoft.com/library/en-us/wmplay/mmp_sdk/windowsmediaplayer9seriessdk.asp
>
> Please do not send email directly to this alias as this alias is for
> newsgroup purposes only. This posting is provided "AS IS" with no
> warranties, and confers no rights. You assume all risk for your use. ©
2004
> Microsoft Corporation. All rights reserved.
>
> "Martin Maher" <mmaher@rochester.rr.com> wrote in message
> news:MPG.1af43102dd730e70989680@news-server.nyroc.rr.com...
> > [This followup was posted to microsoft.public.windowsmedia.sdk and a
> > copy was sent to the cited author.]
> >
> > I apologize for the length of this message, but I felt I had to include
> > some details about what is happening.  I have an application that has to
> > run 24 X 7.  It displays static graphics (JPEGS,BMP's, etc.) as well as
> > streaming video.  I am using the Windows Media Player control to handle
> > the streaming video.  I am using the following interfaces from the WMP
> > control:
> >
> >    IWMPPlayer4
> >    IWMPSettings
> >    IWMPControls
> >
> > I call the WMP control from a DLL.  Here is a summary of what my DLL is
> > doing.
> >
> > HRESULT CStreamPlayer::InitializePlayer()
> >    {
> >    HRESULT hr;
> >
> >    hr = CoCreateInstance(CLSID_WindowsMediaPlayer, NULL,
> > CLSCTX_INPROC_SERVER, IID_IWMPPlayer4, (void **)&pWP);
> >    if (FAILED(hr))
> >       {
> >       return hr;
> >       }
> >
> >    // QueryInterface for Settings interface
> >    hr = pWP->QueryInterface(IID_IWMPSettings, (void **)&pWPSet);
> >    if (FAILED(hr))
> >       {
> >       ReleaseInterfaces();
> >       return hr;
> >       }
> >
> >    // QueryInterface for Controls interface
> >    hr = pWP->QueryInterface(IID_IWMPControls, (void **)&pWPCtrl);
> >    if (FAILED(hr))
> >       {
> >       ReleaseInterfaces();
> >       return hr;
> >       }
> >
> >    return (hr);
> >    }
> >
> > HRESULT CStreamPlayer::PlayMovieInWindow()
> >    {
> >    HRESULT hr = S_OK;
> >    VARIANT_BOOL option;
> >    BSTR bstrFileName;
> >    int nConvertedLen, len;
> >
> >    hr = InitializeInterfaces();
> >    if (FAILED(hr))
> >       {
> >       return hr;
> >       }
> >
> >    // Attach media player to our window
> >
> >    hr = AtlAxAttachControl(pWP,m_hWnd,NULL);
> >    if (FAILED(hr))
> >       {
> >       SetLastErrorMsg("Failed to attach control to playback window");
> >       return hr;
> >       }
> >
> >    // Turn off the context menus and the controls
> >    option = VARIANT_FALSE;
> >    pWP->put_enableContextMenu(option);
> >    pWPSet->put_enableErrorDialogs(option);
> >    pWP->put_windowlessVideo(option);
> >
> >    len = strlen(m_mediaFileName) + 1;
> >    nConvertedLen = MultiByteToWideChar
> > (CP_ACP,0,m_mediaFileName,len,NULL,NULL);
> >    bstrFileName = SysAllocStringLen(NULL,nConvertedLen);
> >    if (bstrFileName != NULL)
> >       {
> >       MultiByteToWideChar(CP_ACP,0,m_mediaFileName,-
> > 1,bstrFileName,nConvertedLen);
> >       pWP->put_URL(bstrFileName);
> >       SysFreeString(bstrFileName);
> >       }
> >    else
> >       {
> >       SetLastErrorMsg("Could not allocate memory for put_URL BSTR");
> >       return hr;
> >       }
> >
> >    pWPCtrl->play();
> >    return hr;
> >    }
> >
> > void CloseClip()
> >    {
> >    pWPCtrl->stop();
> >    pWP->close();
> >    ReleaseInterfaces();
> >    }
> >
> > void CStreamPlayer::ReleaseInterfaces(void)
> >    {
> >    SAFE_RELEASE(pWPCtrl);
> >    SAFE_RELEASE(pWPSet);
> >    SAFE_RELEASE(pWP);
> >    }
> >
> > I am running a test that runs a video every minute for a duration of 30
> > seconds (test was run on 2 XP systems and a Win2000 system).  The test
> > will run for about 10 hours (about 600 events) and then playback fails.
> > The first signs of trouble are a first chance exception that occurs in
> > MSXML3.DLL (Windows Media Player calls this function to parse video
> > parameter files).  I downloaded the current service pack for MSXML3 but
> > it made no difference in the results.  I'm using the runtime library
> > memory debugging routines to find memory leaks (see the MSDN article
> > 'Detecting and Isolating Memory Leaks Using Microsoft Visual C++'), but
> > there do not appear to be any in my code  I also verified that I am
> > releasing all of my Media Player interface pointers after each playback.
> > Task manager is showing an allocation (page file usage) of about 32,000
> > bytes that never gets released every time the test is run.  I have
> > attempted to free memory by unloading my stream player DLL after every
> > playback, but this does not release memory.  Exiting the program does
> > release the memory.  If I restart the test after exiting the program,
> > everything is fine for another 600 playbacks.  However, unloading the
> > EXE is not an option, since it is running as a service and will be
> > performing other tasks.  Has anybody else had similar experiences with
> > the Windows Media Player Control?
> >
> >
> > mmaher@rochester.rr.com
>
>


Relevant Pages

  • Re: IDocHostUIHandler or IDocHostUIHandler2 ?
    ... interface on the host or another class, so long as you inform the WebBrowser ... control when the document load is complete, as you need the document to get ... and I realized that the QueryInterface was never ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Roguelike Interface
    ... No matter how much information you do display, ... the actual interface. ... really important for the player to know each of his attributes at all ... there's no need for a different commands for wear and wield. ...
    (rec.games.roguelike.development)
  • [NEWS] HelixPlayer Based Players Format String
    ... Get your security news from a reliable source. ... media player for Linux, Solaris (versions for other operating systems are ... between 0x0822** - 0x082f** and with control of one pointer at a time ... $ An open security advisory #13 - RealPlayer and Helix Player Remote ...
    (Securiteam)
  • Re: When to Pushout
    ... returning the shot does not change the odds of winning the game. ... player I have ever met understands. ... control of the table and determines what shots are available to his ...
    (rec.sport.billiard)
  • Re: new here, my lang project...
    ... the precondition is usually fairly easy to ... capture the overall solution flow of control. ... the AI should be just as externalized as the player. ... the AI should be an application unto itself that encapsulates all the ...
    (comp.object)