Hello
Is your problem solved?
If the above reply is helpful to you, please mark your reply as an answer, thank you very much!
If you have any further questions, please do not hesitate to contact us.
Thanks
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
We are trying to run multiple h264 videos in a loop using MediaElement class in C# WPF windows application. We ran into out of memory exception after running it for a while.
We observed unmanaged memory shooting up more than a GB.
Please find the environment details:
.Net framework version: 4.8
Windows OS: Win 10
GPU: Intel Graphics HD 520 (internal)
Any idea on how to resolve this?
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hello
Is your problem solved?
If the above reply is helpful to you, please mark your reply as an answer, thank you very much!
If you have any further questions, please do not hesitate to contact us.
Thanks
Hello
It sounds like you’re encountering a memory leak issue with the MediaElement class in your WPF application. Here are a few suggestions to help mitigate this problem:
1.Unregister Event Handlers: Ensure that you unregister any event handlers when they are no longer needed. For example, if you have an event handler for MediaEnded, make sure to unregister it when the media element is no longer in use:
myMediaElement.MediaEnded -= myMediaElement_MediaEnded;
2.Dispose of MediaElement Properly: Explicitly set the Source property of the MediaElement to null and call the Close method when you are done with a video:
myMediaElement.Stop();
myMediaElement.Source = null;
myMediaElement.Close();
3.Turn Off Hardware Acceleration: Sometimes, hardware acceleration can cause issues. You can turn it off by setting the render mode to software only:
protected override void OnSourceInitialized(EventArgs e)
{
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
HwndTarget hwndTarget = hwndSource.CompositionTarget;
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
base.OnSourceInitialized(e);
}
4.Use a Different Media Player: If the issue persists, consider using a different media player library like VLC or FFmpeg which might handle memory management more efficiently.
5.Monitor and Profile Memory Usage: Use tools like the Visual Studio Diagnostic Tools or dotMemory to monitor and profile your application’s memory usage. This can help you identify specific areas where memory is not being released properly.
Implementing these suggestions should help reduce the memory consumption and prevent the out-of-memory exceptions you’re experiencing.