2011-09-14 5 views
1

1つのTextBoxを含む2つの単純なXAMLファイルを作成しました。バインディングを使用するときのメモリ使用

最初のテンプレートは、静的なテキスト使用しています:2番目のテンプレートは、Textプロパティのバインディングを使用しています

<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="Static Text" /> 
    </Grid> 
</Page> 

を:

<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> 

私は常に、ループでメモリ使用量をテンプレートを読み込みますバインディングでテンプレートを使用すると増加します。

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)); 
} 

バインディングを使用すると、使用率は一定になりますか?

+0

どのようにメモリーを測定していますか? GCによって収集されなかったデッドバインディングオブジェクトを測定していませんか? –

+0

私はProcessExplorerを使用してメモリ使用量を測定します。ループが十分に長く実行されると、OutOfMemoryExceptionが発生します。 – Daniel

答えて

0

カスタムを実装することで問題を解決しました。MarkupExtensionのバインドは、アプリケーションがシャットダウンされるまでガベージコレクションされません。

関連する問題