Description
.NET version
.NET 9.0
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
I have a specific usage pattern with a DataGridView
where I pre-create a set of DataGridViewRow
instances and then dynamically add or remove these rows from an existing DataGridView
at runtime.
Here’s how I currently manage rows:
-
Add
– I use this to add pre-createdDataGridViewRow
objects to theDataGridView
. This works as expected. -
Clear
– I use this to remove all rows at once. This also works correctly and does not seem to cause any issues. -
RemoveAt
– I frequently use this to remove rows at specific indices. However, I've noticed that repeated use ofRemoveAt
appears to cause memory leaks over time.
This suggests that RemoveAt
may not be fully disposing of internal row resources or references.
Steps to reproduce
I’ve created a minimal reproducible codebase that demonstrates the issue:
I'm observing unexpected memory behavior after adding and removing DataGridViewRow
objects repeatedly. Specifically, memory snapshots reveal a buildup of tooltip-related objects even after rows are removed.
📸 Memory Snapshot Before Hide/Show
:
📸 Memory Snapshot After One Hide/Show
Cycle:
As shown, there's a significant increase in:
-
ConditionalWeakTable+Entry<IKeyboardToolTip, WeakReference<ToolTip>>[]
-
WeakReference<ToolTip>
These objects appear to accumulate with each hide/show cycle, and may not be getting released properly, potentially indicating a memory leak related to tooltip handling in DataGridViewRow
.
I'm looking for guidance on:
-
Whether this is a known issue with
DataGridView
tooltip internals. -
Recommended practices to avoid or mitigate this kind of memory retention when programmatically adding/removing large numbers of rows.