WPF memory leak on XP (CMilChannel, HWND)

My WPF application leaks memory around 4kb / s. The memory usage in the task manager constantly rises until the application crashes with the exception β€œNot enough memory”.

After conducting my own research, I found that the problem is discussed here: Track memory leak in WPF and # 8 here: http://blogs.msdn.com/jgoldb/archive/2008/02/04/finding-memory-leaks-in- wpf-based-applications.aspx

The described problem: This is a leak in WPF, present in versions of the framework up to .NET 3.5 SP1. This is because WPF chooses which HWND to use to send messages from the rendering stream to the user interface stream. This pattern destroys the first HWND created and starts the animation in a new window. This leads to the fact that messages sent from the rendering stream accumulate without processing, effectively memory leak.

Proposed Solution: A workaround is to create a new HwndSource in its App class constructor. It MUST be created before WPF creates any other HWND. By simply creating this HwndSource, WPF will use this to send messages from the visualization stream to the user interface stream. This ensures that all messages are processed and that no one leaks.

But I do not understand the solution! I have a subclass of the application that I am using and I tried to create a window in this constructor, but this did not solve the problem.

Following the instructions given literally, it looks like I just need to add this to my application constructor:

new HwndSource(new HwndSourceParameters("MyApplication")); 
+4
memory-leaks windows-xp wpf hwnd
source share
1 answer

Correction:

Application.xaml.cs

 class MyApp1 : Application { // ... public Application() { new HwndSource(new HwndSourceParameters()); } // ... } 
+6
source share

All Articles