WPF TreeView Memory Consumption and Performance
One very simple thing you can do that can significantly reduce the memory consumption and drastically improve performance of a WPF TreeView is to set the following two properties. In XAML, you would do:
<TreeView x:Name=”myTreeView”
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" />
In a simple test of a data-bound TreeView containing just 5000 items, turning on stack panel virtualization reduces the memory overhead from over 110MB to about 2MB. Additionally, the control also gets a performance boost in items’ expand/collapse, selection, scrolling, and general navigation.
The WPF ListView also support these properties but, unlike the TreeView, its VirtualizingStackPanel.IsVirtualizing is already default to True.
Enjoy.
-Tan