Skip to content

Conversation

@LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Jan 20, 2026

Fixes #14204

Root Cause

The foreach loop over DataGridViewRowCollection uses an enumerator that calls this[index], which unshares (clones) each shared row. For 700k rows, this causes massive memory allocation and CPU usage.

Proposed changes

  • DataGridView.Methods.cs:
    • Added ReleaseRowUiaProviders() helper method
    • Modified ReleaseUiaProvider() to use HashSet deduplication instead of foreach
  • DataGridViewColumnCollection.cs:
    • Modified RemoveAtInternal() to use HashSet deduplication

Customer Impact

  • Applications with large DataGridView (700k+ rows) freeze for several seconds when closing forms or removing columns

Regression?

  • Yes (The regression was introduced in this commit)

Risk

  • Minimal

Screenshots

Before

Closing a form with 700k rows causes 5-10+ seconds of UI freeze and high memory spike due to row cloning.

After

Form closes near-instantly with minimal memory overhead.

Test methodology

  • Manual test

Test environment(s)

  • .net 11.0.0-alpha.1.26057.107
Microsoft Reviewers: Open in CodeFlow

@LeafShi1 LeafShi1 requested a review from a team as a code owner January 20, 2026 10:21
@LeafShi1 LeafShi1 marked this pull request as draft January 20, 2026 10:21
@LeafShi1
Copy link
Member Author

This fix requires further testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataGridView: Excessive CPU+memory usage when closing form

1 participant