开发者

Memory usage when using binding

开发者 https://www.devze.com 2023-04-04 23:13 出处:网络
I created two simple XAML files which contain a single TextBox. The first template uses a static text:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消