Memory Optimization for ItemsRepeater with 600,000 Items in AvaloniaUI 11.1.0 beta 1 #15600
-
I have implemented an ItemsRepeater in my AvaloniaUI application to display a list of approximately 600,000 items. The current code works, but it consumes around 600 MB of RAM, which is concerning in terms of performance and resource usage. Here is the code I am currently using: <ItemsRepeater ItemsSource="{Binding FileResults}">
<ItemsRepeater.Layout>
<StackLayout Spacing="5" DisableVirtualization="False"
Orientation="Vertical" />
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<!-- My Item -->
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater> I am looking for ways to optimize memory usage to efficiently handle this number of items. I am currently using AvaloniaUI version 11.1.0 beta 1. Any suggestions or best practices to improve ItemsRepeater performance and reduce memory consumption would be greatly appreciated. Thank you in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Just started with Avalonia, so I might be wrong. It seems like the Repeater is not using virtualization by default, or maybe cannot have it. |
Beta Was this translation helpful? Give feedback.
-
I display ~3k bitmaps in one of my apps using the items repeater and rarely get more than ~200mb-300mb memory usage (when loading images from the cache, resizing them to put into the cache is a different story). I can get this down to a rock solid ~150mb by just force disposing the bitmaps when they are not needed any more. |
Beta Was this translation helpful? Give feedback.
You seem to be using Marshal and native pointers. Without seeing the rest of your code it's possible you may have a memory leak, if you do not ever free the native memory allocated to the pointers region.
It also looks like you are eager loading your data, as such based on some quick math and some assumptions:
Which means you are looking at roughly 388 bytes per object. Multiply that by 600000 you get 232 megabyt…