dotnet / dotnet/winforms

DataGridView not dispose old elements

Open
#6,859 11 comments 0 reactions 0 assignees View on GitHub
area-controls-DataGridView help wanted tenet-performance
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

* .NET Core Version: all up to 7.0 p2

* Have you experienced this same bug with .NET Framework?: Yes

**Problem description:**
As I mentioned in https://github.com/dotnet/winforms/issues/6858 `DataGridView` not dispose old data on `DataSource` change. This is lead to 2 problems:
1. All this stuff are going to finalization query because we have unnecessary finalizer here #6858.
2. If we have a `ContextMenuStrip` bound to Cell/Column/Row we will have a memory leak. `DataGridView` with 3 columns and `ContextMenuStrip` bound to 1000 rows, result of DS refresh:
![image](https://user-images.githubusercontent.com/17767561/158846287-aebb7710-09c2-45f5-8428-6f4ebe9812cd.png)

**Expected behavior:**
Old data must be property disposed. Probably in `DataGridView.RefreshColumnsAndRows()` (in `DataGridView.Methods.cs`)

**Minimal repro:**
[DataGridViewLeak.zip](https://github.com/dotnet/winforms/files/8288127/DataGridViewLeak.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.