And if we profile the application, we will see this as well.After running our application and making a large number of changes to a textbox’ contents, the dot Memory snapshot overview could show a large number of and try focusing on other dominators if the allocations are too excessive.The Shortest Paths to Roots Tree view will tell us which event we’re subscribing to.From the investigation above, we know which event and which event handler we’ve forgotten to unsubscribe from ( constructor).
WPF creates a strong global reference to the UI element that is declared in XAML if it uses the x: Name directive.
In the snapshot overview page, we will immediately see if the object remained in memory because of an event handler leak. dot Memory detected it is kept in memory because of an event handler leak.
Now how to find out which event handler is keeping it in memory…
We can drill down and look at the Key Retention Paths to see WPF is retaining our object in memory.
To ensure the control gets removed from memory, we will have to call the method of the parent control.