Re: Windows Media Player Memory Leak

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

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


Date: Sun, 25 Apr 2004 10:22:35 -0700

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: Controlling Media Player Programatically
    ... > The Media Player SDK was for an old Pocket PC. ... > Windows Media Player 10, just now coming out on the very latest Pocket ... > does have an automation interface through an ActiveX control. ... >> app or alternatively manipulate the already running player with some ...
    (microsoft.public.pocketpc.developer)
  • Re: How can I use IWMPSyncServices in Media Player 10 SDK?
    ... I adding an Embedded Windows Media Player Control in my program. ... >> Are you instantiating the control in remote mode? ...
    (microsoft.public.windowsmedia.sdk)
  • Clicking on a WMV file in Explorer causes error...
    ... memory could not be "read". ... These files work on other machines, ... Windows Media Player is version 10. ...
    (microsoft.public.windowsxp.general)
  • Re: Windows media player metaphysical questions
    ... I am able to see some of them through Control ... use the Internet Explorer Windows Media Player stand-alone. ... installed a decoder dll. ...
    (microsoft.public.windowsmedia)
  • Re: Controlling Media Player Programatically
    ... The Media Player SDK was for an old Pocket PC. ... Windows Media Player 10, just now coming out on the very latest Pocket PCs, ... Hosting the Windows Media Player 10 Mobile control in Windows CE ...
    (microsoft.public.pocketpc.developer)