Home > Net >  Xamarin/.net maui - Updating collectionview itemsource causing memory leak
Xamarin/.net maui - Updating collectionview itemsource causing memory leak

Time:02-10

I have a collectionview and a picker, the picker allows you to filter the collectionview items by a specific property of a collectionview item. To achieve this I am setting the collectionview itemsource again each time the picker is changed. How do I change the things that are displayed in the collectionview differently to prevent the memory from creeping up every time.

I am also doing the same thing re-setting the itemsource when adding a new item to the collectionview.

Also it is just a standard List as the itemsource for the collection which is set via x:Name instead of binding. I've seen some things on Observable collections -- would that make the difference to update the observable collection and make the itemsource binding ? -- Would that live update as an item in the collectionview gets added/removed?

A little example code:

string selectedItem = Picker_Category.SelectedItem.ToString();     
List<Items> items = await App.Database.ReadItems();
var listy = items.Where(t => t.Category.ToLower().Contains(selectedItem.ToLower())).ToList();


Items_CollectionView.ItemsSource = listy;

CodePudding user response:

  •  Tags:  
  • Related