Memory leak due to Window.EfectiveValues retention

1.5k views Asked by At

I'm experiencing a memory leak in my WPF application.

I want to GC my DiffViewControl, but it's retained by the Window.EffectiveValues instance. enter image description here

Do you know how could I clean this obsolete reference and then the DiffViewControl can be GC'd?

1

There are 1 answers

1
Daniel Peñalba On BEST ANSWER

Finally I figured out the problem after reading this post:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/1283a5da-48c2-4398-9064-a92f569d657d/wpf-textboxfocus-results-in-usercontrol-garbage-collection-problem?forum=wpf

My problem is that if I close the WPF window, and a textbox in that window has the focus, the textbox is leaked, so the entire window is leaked.

The solution in my case is removing the focus from any textbox in the window before closing it.

Keyboard.ClearFocus();