Skip to content

DataGridView memory leakage when removing rows with RemoveAt #13593

Open
@Lephat902

Description

@Lephat902

.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-created DataGridViewRow objects to the DataGridView. 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 of RemoveAt 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:

📁 WinFormsApp1.zip

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:

Initial Snapshot

📸 Memory Snapshot After One Hide/Show Cycle:

After Hide/Show

Image

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions