How to avoid memory leaks in mediaplayer

Topics: Windows Phone 8
Nov 26, 2013 at 6:35 AM
What is the proper way to dispose of the mediaplayer in order to avoid memory leaks and circular references? I profiled my app using the vs memory tool and when I opened and closed the page which contained the media player I saw multiple references to it.

I'm currently doing something like this in the unloaded event:
    private void MPlayer_Unloaded(object sender, RoutedEventArgs e)
        MPlayer = null;
Anything else that needs to be done to avoid leaks?
Dec 4, 2013 at 7:20 PM
This is correct except calling .Close() is unnecessary as .Dispose() will internally do this first if necessary.

Also make sure you remove it from the visualtree if reusing the same page in your app without the control.