CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2011
    Posts
    4

    Memory Leaks in Window Media Player + c#

    Hi

    I am facing some memory leaks in windowmediaplayer after disposing it.
    Following is the code

    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    AxWMPLib.AxWindowsMediaPlayer m = new AxWMPLib.AxWindowsMediaPlayer();

    private void start_Click(object sender, EventArgs e)
    {
    this.Controls.Add(m);
    m.Location = new System.Drawing.Point(1, 1);
    m.Height = 130;
    m.Width = 150;

    m.URL = @"C:\Users\Public\Videos\Sample Videos\Bear.wmv";
    }

    private void stop_Click(object sender, EventArgs e)
    {
    m.URL = null;
    m.close();
    m.Dispose();

    }
    }

    On clicking stop, it is still keeping the following in the memory

    System.Windows.Forms.AxHost.ConnectionPointCookie
    AxWMPLib.AxWindowsMediaPlayerEventMulticaster


    Please Help

    Thanks

  2. #2
    Join Date
    Feb 2010
    Posts
    29

    Re: Memory Leaks in Window Media Player + c#

    Pankaj Safaltek,

    Try the following:

    Code:
    private void stop_Click(object sender, EventArgs e)
    {
        m.URL = null;
        m.close();
        m.Dispose();
        Marshal.FinalReleaseComObject(m);
    }
    Regards,
    bassguru

  3. #3
    Join Date
    Feb 2011
    Posts
    4

    Re: Memory Leaks in Window Media Player + c#

    Hi

    I am getting the following crash
    The object's type must be __ComObject or derived from __ComObject.
    Parameter name: o


    On the execution of following code.

    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(m);

    Please help.

  4. #4
    Join Date
    Feb 2010
    Posts
    29

    Re: Memory Leaks in Window Media Player + c#

    Try the following:

    Code:
    private void stop_Click(object sender, EventArgs e)
    {
        bool test1 = false;
        bool test2 = false;
    
        test1 = System.Runtime.InteropServices.Marshal.IsComObject(m);
        m.URL = null;
        m.close();
        m.Dispose();
        test2 = System.Runtime.InteropServices.Marshal.IsComObject(m);
    }
    Are test1 and test2 both false after running?

  5. #5
    Join Date
    Feb 2011
    Posts
    4

    Re: Memory Leaks in Window Media Player + c#

    Yes, Both are false.

  6. #6
    Join Date
    Feb 2010
    Posts
    29

    Re: Memory Leaks in Window Media Player + c#

    Try the following:

    Code:
    private void stop_Click(object sender, EventArgs e)
    {
        m.URL = null;
        m.close();
        m.Dispose();
        m = null;
    }
    Does that stop the momory leak?

  7. #7
    Join Date
    Feb 2011
    Posts
    4

    Re: Memory Leaks in Window Media Player + c#

    No

  8. #8
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Memory Leaks in Window Media Player + c#

    Do you need to create this every time you start and destruct it every time you stop a video?

    Perhaps

    PHP Code:
    using (= new mediaplayer())
    {
                
    Application.Run(new MediaForm(m));

    This link may give you some ideas:
    http://www.devx.com/dotnet/Article/39023
    ahoodin
    To keep the plot moving, that's why.

  9. #9
    Join Date
    Nov 2011
    Posts
    1

    Re: Memory Leaks in Window Media Player + c#

    Hello guys, I'm having the same problem.

    I really need to remove the component e after add.

    Could you help me???

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured