Is there a memory leak if we set the ItemSource property of the control to null in WPF?

I have a TabControl that has two TabItems. Each of these two TabItems has a list. In the SelectionChanged event handler, I set the ItemSource property of the corresponding ListBox to null and populate it with a collection. Now, as I continue to select each tab, there is a burst of memory. Why is this?

+3
source share
2 answers

Do not try to clear the lists when changing the tabs, I do not think that WPF will try to draw the list if it is not displayed. When I need to make listbox / itemscontrol display a collection of objects, I do this:

//have all the usual usings and
using System.ComponentModel
using System.Collections.ObjectModel
class Bar : INotifyPropertyChanged
{
   //make your properties setters call PropertyChanged
}
class Bars : ObservableCollection<Bar>
{
}

, ItemsSource Bars, Bar. , ItemsSource (becuase ObservableCollection , , - ), , , . ItemsSource , , , :), , Red-Gate .net, , ListBox.

, , , , , ListBoxes , .

+1

, TabControl - ItemsControl. http://msdn.microsoft.com/en-us/library/system.windows.controls.tabcontrol.aspx

.

, Task Factory.

, null:)

0

Source: https://habr.com/ru/post/1755256/


All Articles