Avalonia 版本号:11.3.7, 11.3.9
Antelcat.I18N.Avalonia 版本号:1.1.2
这个TextBlock是一个DataGrid中的一列,共有500行,跟随一个ListBox选中的项来更新显示这500行的内容,在ListBox中两项之间来回切换选中项,每切换一个内存有约6MB至8MB大小的增长,注释掉这条或者不使用I18N时,来回切换选中项内存不会增长。ListBox有200行,其它地方的也用到这样的绑定,随便点一点,内存就增长到2GB以上.
<TextBlock Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{I18N {Binding FuncString}}" />
后来,注释public NotifyAccessor(I18NExtension.ResourceChangedNotifier notifier) 中的 this.notifier.PropertyChanged += OnPropertyChanged; 来回切换选中项内存几乎不增长。
public NotifyAccessor(I18NExtension.ResourceChangedNotifier notifier)
{
this.notifier = notifier;
this.notifier.PropertyChanged += OnPropertyChanged;
}
再后来注释掉 static I18NExtension() 中的 BindingPlugins.PropertyAccessors.Insert(0, NotifierPropertyAccessorPlugin.Instance); 后,来回切换选中项约100次,内存增长约50MB。
static I18NExtension()
{
var target = new LanguageDictionary();
Target = target;
Notifier = new ResourceChangedNotifier(target);
SourceBinding = new(nameof(ResourceChangedNotifier.Source))
{
Source = Notifier,
Mode = BindingMode.OneWay,
};
BindingPlugins.PropertyAccessors.Insert(0, NotifierPropertyAccessorPlugin.Instance);
lock (ResourceProvider.Providers)
{
foreach (var provider in ResourceProvider.Providers) RegisterLanguageSource(provider);
ResourceProvider.Providers.CollectionChanged += (_, e) =>
{
if (e.Action != NotifyCollectionChangedAction.Add) return;
foreach (var provider in e.NewItems.OfType<ResourceProvider>())
{
RegisterLanguageSource(provider);
}
};
}
}
Avalonia 版本号:11.3.7, 11.3.9
Antelcat.I18N.Avalonia 版本号:1.1.2
这个TextBlock是一个DataGrid中的一列,共有500行,跟随一个ListBox选中的项来更新显示这500行的内容,在ListBox中两项之间来回切换选中项,每切换一个内存有约6MB至8MB大小的增长,注释掉这条或者不使用I18N时,来回切换选中项内存不会增长。ListBox有200行,其它地方的也用到这样的绑定,随便点一点,内存就增长到2GB以上.
<TextBlock Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{I18N {Binding FuncString}}" />后来,注释public NotifyAccessor(I18NExtension.ResourceChangedNotifier notifier) 中的 this.notifier.PropertyChanged += OnPropertyChanged; 来回切换选中项内存几乎不增长。
再后来注释掉 static I18NExtension() 中的 BindingPlugins.PropertyAccessors.Insert(0, NotifierPropertyAccessorPlugin.Instance); 后,来回切换选中项约100次,内存增长约50MB。