Memory usage when using binding
I created two simple XAML files which contain a single TextBox.
The first template uses a static text:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBox Heig开发者_开发百科ht="20" Width="120" Text="Static Text" />
</Grid>
</Page>
The second template uses a binding for the Text property:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBox Height="20" Width="120" Text="{Binding Path=Test}" />
</Grid>
</Page>
When I load the template in a loop, the memory usage constantly increases when I use the template with the binding:
while (true)
{
// Memory usage increases
var binding = Application.LoadComponent(new Uri("/ConsoleApplication1;component/Binding.xaml", UriKind.Relative));
// Memory usage stays constant
//var noBinding = Application.LoadComponent(new Uri("/ConsoleApplication1;component/NoBinding.xaml", UriKind.Relative));
}
Any ideas how the memory usage can be constant when using bindings?
We solved the problem by implementing a custom MarkupExtension. The default Binding is not garbage collected until the application is shut down.
精彩评论