WPFLocalizeExtension: Localization within border ctrl seems to cause Memory Leak

Describe the bug We used lex:Loc extension to translate a TextBlock within a BorderCtrl. After checking the Memory consumption with JetBrains dotMemory tool we saw a slightly increase of the “inner” dictionary of ParentNotifiers used in public static T GetValueOrRegisterParentNotifier<T> of ParentChangedNotifierHelper. It looks like the references are set to “null” before the ParentNotifier Dictionary is updated correctly. Then the key will no longer be found and added again. We tried the same with a Label Control inside a Border Ctrl but this made no change to the memory. As the parent control has multiple instances the dictionary was over 10.000 entries after few hours. We’ve ended up to use a Label and manipulate the direct border of the Label instead of using a derived class from Border (which worked)

To Reproduce We use default Resource Manager to handle translations! We used a simple BorderEx Control (derived from Border Control) with the following XAML. The Control was within another Control which was dynamically created and deleted every few seconds. All other ParentNotifiers were handled correctly but not that one of the TextBlock.

<Border ....>
    <Border.Resources>
        <Style TargetType="slot:BorderEx">
            ...
    </Border.Resources>

    <TextBlock Text="{lex:Loc disabled}" HorizontalAlignment="Center" VerticalAlignment="Center" 
               Visibility="{Binding ShowSelectionBorderDisabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type slot:BorderEx}}, Converter={StaticResource BoolToVisibilityConverter}}" />

</Border>

To reproduce it should be enough to create a UserControl, put the Border Control in it and regularly dismiss and newly create the userControl to see the growing Dictionary. I did not investigate it deeper and I can’t share more of the Code. Maybe it has something to do with the whole code we use. Just wanted to give a hint, because this one was a major issue on our side as any memory leak can have huge effects.

Expected behavior All ParentNotifier should be cleared when Parent is garbage collected.

Enviroment (please complete the following information):

  • OS: Windows 10
  • .NET Framework: [NET47]
  • Latest Release of WPFLocalizeExtension

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (13 by maintainers)

Most upvoted comments

Seems to be working fine if I start without debugging, i dump a couple of times (collect + add) until i get zero count/alive. I then attach the debugger and take a snapshot. It returns to 1. I guess the live visual tree still holds some refs when running directly in debug mode.

Thanks for taking the time to fix it. Cheers!

image