I have a UserControl in an application where I am constantly swapping the Content property with other UIElements.
However I noticed in Task Manage after a while the memory goes up after a number of swaps...
Using AntProfiler I noticed for some reason there ToolBarAutomationPeer that the UserControl references....
To fix this Memory leak I made my own usercontrol with the following code
public class MyUserControl : UserControl
{
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return null;
}
}
This seems to remove any AutomationPeers that THe usercontrol may reference that may keep the Content that I am swapping in memory...
But I am still interested to know how did a ToolBarAutomationPeer get into my UserControl and what are the ramifications of me returning null in the OnCreateAutomationPeer method?
I am not well versed with Automation callses and not sure when they would be useful
Thanks
The automation kicks in if you have an automation client running on your computer. The most common being:
This makes silverlight a complete mess and causes a number of bugs, and almost-always makes everything leak like crazy.
I disabled automation by setting this parameter in my html:
You can read more here: Silverlight + MVVM + Bindings = Memory leaks?
I would be curious to see more code to try to figure out why the ToolBarAutomationPeer is appearing also but basically the automation peers are for accessibility. Screen readers and other automation tools can use the automation peers to run your application. Common uses are for people who are handicapped in one way or another and also test automation tools.
By returning null like you are above you are making your usercontrol completely innaccessible to automation.