[MVU] Changing theme takes too long, ItemsRepeater seems to not dispose items ???? #2395
-
This one is tricky.... let's create a simple MVU model with the list state internal record Item(string Text, Brush Brush);
internal partial record MainPageModel
{
public IListState<Item> Items => ListState<Item>.Value(this, () =>
[
new Item("A", new SolidColorBrush(Colors.DeepSkyBlue)),
new Item("B", new SolidColorBrush(Colors.DarkOrchid)),
]);
} Let connect the list state to the view: new ScrollViewer()
.Content(
new ItemsRepeater()
.ItemsSource(() => vm.Items)
//.Layout(new StackLayout()) // this is virtualizing layout
.Layout(new NonVirtualStackLayout()) // this is non-virtualizing layout
.ItemTemplate<Item>(item => GetItemView(item))
)
private static Grid GetItemView(Item item) => new Grid().Children(
new Rectangle()
.Width(100)
.Height(20)
.Stroke(Colors.Black)
.StrokeThickness(1)
.Fill(Themes.MyBrush) // themes binding
.Margin(3),
new TextBlock()
.Text(() => item.Text)
.VerticalAlignment(VerticalAlignment.Center)
.HorizontalAlignment(HorizontalAlignment.Center)
.Foreground(() => item.Brush)
); Please note the Themes binding used in the item internal static class Themes
{
public static readonly Resource<Brush> MyBrush = ThemeResource.Create<Brush>(nameof(MyBrush),
new SolidColorBrush(Colors.LightBlue), new SolidColorBrush(Colors.LightCoral));
} This app works like a charm with both virtualizing layout and non-virtualizing layout: The app allows to add more items to the list and switch the light/dark mode. All good. Issue 1 When a number of the items grows, the time of theme switch takes surprisingly very long time: with 2000 items created it takes more then 10 sec (debug). Issue 2 I do not understand why it so, but it seems to me, that somehow removed items still persist and influence the app. If items remain indeed undisposed, this issue would be hidden when using any of virtualizing layout... Remarks:
repro: UnoThemeTooSlowApp.zip |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Please conduct following experiments: Experiment 1
The result of the test is following on my computer:
Test performed in release mode, no debugger attached. As you see, memory usage always grows, never shrinks. Experiment 2
The result of the test is following on my computer:
As you see, memory usage grows consequently, it shrinks as well a bit, but is far away (100 MB) of memory used when items have been shown for the first time. Important I guess that, items are not properly disposed. Please note, that this test has been performed on newest build: |
Beta Was this translation helpful? Give feedback.
Will close this discussion in favor of #2428