I don't know why but when I define the ItemsSource of my DataGrid, it creates some memory leak.
This is the xaml code of my DataGrid:
<DataGrid x:Name="DataGrid1" AutoGenerateColumns="True" IsReadOnly="True" ClipboardCopyMode="ExcludeHeader" Margin="20,250,20,20" SelectionUnit="Cell" Style="{DynamicResource MaterialDesignDataGrid}" SelectionMode="Single"/>
And this is the code behind where I define the ItemsSource:
cmd = New SqlCommand With {
.CommandText = strsql,
.Connection = DBConn.ADONETconn
}
da = New SqlDataAdapter(cmd)
dt = New DataTable("RECH")
da.Fill(dt)
DataGrid1.ItemsSource = dt.DefaultView
As you can see from the diagnostic tool, I have some memory leak somewhere.
I know it's caused by the line DataGrid1.ItemsSource = dt.DefaultView
because if I comment it, the memory leak doesn't occur.
I've downloaded JetBrains dotMemory to see what's going on. As you can see bellow, it tells me that it's caused by DataGridRow.
I don't understand why this happens. The data is correct in the DataTable.
If you have any clues, please share them with me
Found. Actually it came from the fact that my DataGrid was in a StackPanel. And I still don't know why but it was a problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.