Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory leak due to Window.EfectiveValues retention

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?

like image 698
Daniel Peñalba Avatar asked Jun 15 '15 15:06

Daniel Peñalba


1 Answers

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();
like image 68
Daniel Peñalba Avatar answered Oct 02 '22 22:10

Daniel Peñalba