WP7 MediaElement Memory Leak

Currently trying to fix a memory leak.  Don’t have a lot of experience troubleshooting these so figured I would post about.  The memory leak occurs when you replay a MediaElement in the MediaEnded event.

I started with a new WP7 app added the following xaml to the page:

<MediaElement AutoPlay=”True” Source=”MyShortMovie.wmv” MediaEnded=”MediaElement_MediaEnded”/>

and the following to the code behind:

private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
var element = (MediaElement)sender;
element.Position = TimeSpan.FromSeconds(0.0);

Will continue to research and post any findings.  Please leave comments if you have any insight.

Leave a Reply