Closed xDreamms closed 2 weeks ago
The problem I see here is that you load a bitmap for each movie you load, but you never free the bitmaps. The VirtualizingWrapPanel only virtualizes the UI elements. The data you are loading has to be freed by your code when it is no longer needed.
The problem I see here is that you load a bitmap for each movie you load, but you never free the bitmaps. The VirtualizingWrapPanel only virtualizes the UI elements. The data you are loading has to be freed by your code when it is no longer needed.
How can I do that?
Basically, you need to make sure that you dispose the bitmaps that are no longer needed/visible (data virtualization). You can do this, for example, in the ScrollChanged event on a per-page basis, such as in your loading code, or in the DataContextChanged event of the individual elements. Alternatively, you could use some sort of bitmap "pool" with an appropriate maximum size.
I have the same issue on my end, but for me it's caused by using a SharedSizeGroup
on a Grid inside of the item template. This works fine most of the time, but when there are several hundred items in the ListBox it causes the app to freeze and I can see in the Visual Studio debugger how the app memory keeps increasing until it runs out of memory. I should also note that this does not happen when using a normal non-virtualized WrapPanel as the panel of the ListBox.
I do realize that a SharedSizeGroup can be expensive, and the reason I use it is to ensure the height of the items is the same. Is there another approach I can take instead? If I don't do this then the items height appears to be determined by the first item in the list. This causes the bigger items to be clipped so they don't fully display. I know I can set AllowDifferentSizedItems
to true, but then the items end of having different heights, while what I want is to have each item have the same height as the biggest item. Is there another solution to this?
@RayCarrot I don't know how SharedSizeGroup is implemented, but I can't imagine it's such a big problem. Have you analyzed your memory usage? If you are sure that SharedSizeGroup is the cause of the freeze, please open a new issue with steps to reproduce or an sample project. Another approach would be to keep track of the max item height yourself (e.g. using the loaded or size changed event of the root element of your item template) and set the ItemSize property of the VirtualizingWrapPanel accordingly.
Describe your issue After scrolling a lot the application freezes. Error: not enough memory resources to process this command.
I use this https://github.com/jellyfin/TMDbLib
Version Info Package Version 2.0.12 .NET Version: NET 8.0 OS Version: Windows 10 22H2 Build 19045.5011