Reputation: 801
I've got a pivot view, with 6 pivotitems. Each pivotitem contains a list of movies. Each movie has a coverimage, and next to it a title and some other metadata. To style this as I wanted had to use a few grids/stackpanels obviously. Also, i have a contextmenu for each item. Above my listbox I have a performance progress bar to show while the data is loaded (I get everything from a web API). My problem is that one of the lists contains a lot more movies than the others, about 100. When loading this list the app uses around 150-160 mb memory, which exceeds the limit of 90 mb. It looks like all the images and content is loaded right away (which I think causes this problem).
What I would want is this:
Load the title and metadata first, then load the images only where the user is currently at in the list, so that the images longer down the list arent loaded before the user scrolls down to it.
I've tried using deferredloadlist, lazylist and normal listbox, and ive tried setting virtualization to standard and recycling, without results. I must admit im not sure what all those things really do though. Does anyone know how I can fix this? Thanks in advance.
PS. the xaml-code for the listbox is somewhat clunky, so i decided not to include it in this post. Let me know if you really need to look at it to help though.
Update: I've been able to reduce the memory-usage by using virtualizing listboxes, but its still around 100 mb. I read somewhere that setting bitmapImage.ImageSource =null; when finished using an image will clear it from the memory. How can I do this for each image when they're in a listbox?
Upvotes: 3
Views: 1957
Reputation: 1402
The ListBox itself doesn't use much memory. It's the ListBoxItems' contents which do. A virtualizing panel only creates the ListBoxItems which are visible (plus a few more) and destroys off-screen ListBoxItems. So make sure your ListBox uses a virtualizing Panel, e.g. by NOT setting ListBox.ItemsPanel.
For virtualization the Panel needs to have a constrained size - otherwise it would create ALL ListBoxItems. In general this is done by giving the ListBox a constrained size by putting it into a Grid or by setting Width/Height. But if you instead place the ListBox inside a non-constraining container (e.g. ScrollViewer, StackPanel, ...), then the ListBox' size is unlimited, the ItemsPanel will grow as much as it wants and all ListBoxItems are created - even if they're far off-screen.
Upvotes: 4
Reputation: 9230
Did you tryed lazy image downloading?:
public class ItemViewModel
{
private BitmapImage _image;
public BitmapImage Image
{
get{
if(_image == null)
{
_image = new BitmapImage();
StartDownloadImageAsync();
}
return _image;
}
}
}
and after you download an image - set it to _image and call RaisePropertyChanged("Image"); So on vitrualized listbox you will download images only for visible items.
If you did, you may try to Paginate the list.
Upvotes: 1