A memory leak using WPF ListBox and DataTable
<p>I seem to be having a situation which is causing a memory leak.   As I run this code and watch the real-time diagnostics while clicking the "Do It" button, it appears as though my data tables are never being freed.  I don't understand what could be rooting this data.   Could anyone provide me any insight on why this is?  And what can be done about it?</p>

<p><b>MainWindow.Xaml</b></p>

<pre><code>&lt;Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525"&gt;
    &lt;DockPanel&gt;
        &lt;Button Content="Do It" Margin="5 5 5 0" Click="Button_Click" DockPanel.Dock="Top" /&gt;
        &lt;ListBox Margin="5" Name="lister"&gt;
            &lt;ListBox.ItemTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;StackPanel Orientation="Horizontal"&gt;
                        &lt;TextBlock Text="{Binding LastName}" /&gt;
                        &lt;TextBlock Text=", " /&gt;
                        &lt;TextBlock Text="{Binding FirstName}" /&gt;
                    &lt;/StackPanel&gt;
                &lt;/DataTemplate&gt;
            &lt;/ListBox.ItemTemplate&gt;
        &lt;/ListBox&gt;
    &lt;/DockPanel&gt;
&lt;/Window&gt;
</code></pre>

<p><b>MainWindow.Xaml.vb</b></p>

<pre><code>Imports System.Data

Class MainWindow
    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
        Dim tbl As New DataTable
        tbl.TableName = "Contacts"
        tbl.Columns.Add("LastName")
        tbl.Columns.Add("FirstName")
        For idx As Integer = 1 To 50000
            Dim row As DataRow = tbl.NewRow()
            row.Item("LastName") = $"Last {idx}"
            row.Item("FirstName") = $"First {idx}"
            tbl.Rows.Add(row)
        Next
        lister.ItemsSource = tbl.AsDataView()
    End Sub
End Class
</code></pre>