Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/Avalonia.Controls.DataGrid.LeakTests/LeakTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,24 @@ WeakReference Run()
GC.KeepAlive(items);
}

[ReleaseFact]
public void DataGrid_RemovedNotifyDataErrorInfoCell_DoesNotLeak()
{
var items = new ObservableCollection<NotifyDataErrorRowItem>
{
new NotifyDataErrorRowItem("A")
};
items[0].SetErrors(new[] { "Invalid" });

var (grid, cellRef) = RunInSession(() =>
RunRemovedNotifyDataErrorInfoCell(items));

AssertCollected(cellRef);

GC.KeepAlive(grid);
GC.KeepAlive(items);
}

[ReleaseFact]
public void DataGrid_NotifyDataErrorInfo_ErrorsChanged_DoesNotLeak()
{
Expand Down Expand Up @@ -1817,6 +1835,52 @@ private static WeakReference RunColumnDefinitionsSourceSwap(
return gridRef;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static (DataGrid Grid, WeakReference CellRef) RunRemovedNotifyDataErrorInfoCell(
ObservableCollection<NotifyDataErrorRowItem> items)
{
var grid = new DataGrid
{
AutoGenerateColumns = false,
ItemsSource = items
};
grid.Columns.Add(new DataGridTextColumn
{
Header = "Name",
Binding = new Binding(nameof(NotifyDataErrorRowItem.Name))
});

var window = new Window
{
Width = 600,
Height = 300,
Content = grid
};
window.SetThemeStyles();
ShowWindow(window);
grid.ScrollIntoView(items[0], grid.Columns[0]);
Dispatcher.UIThread.RunJobs();
PumpLayout(grid);

grid.SelectedItem = items[0];
grid.CurrentCell = new DataGridCellInfo(items[0], grid.Columns[0], 0, 0);
Dispatcher.UIThread.RunJobs();
Assert.True(grid.BeginEdit());
Dispatcher.UIThread.RunJobs();
var row = Assert.IsType<DataGridRow>(grid.EditingRow);
DataGridCell cell = row.Cells[0];
Assert.True(grid.CancelEdit(DataGridEditingUnit.Cell));
Dispatcher.UIThread.RunJobs();
Assert.True(DataValidationErrors.GetHasErrors(cell));
var cellRef = new WeakReference(cell);

grid.Columns.RemoveAt(0);
Dispatcher.UIThread.RunJobs();
CleanupWindow(window);

return (grid, cellRef);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static (
WeakReference GridRef,
Expand Down
Loading
Loading