-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixing memory leaks of DataGridView elements accessible objects #7349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26104,6 +26104,44 @@ private void ReleaseMouse() | |
| Capture = false; | ||
| } | ||
|
|
||
| internal override void ReleaseUiaProvider(IntPtr handle) | ||
| { | ||
| if (!IsAccessibilityObjectCreated) | ||
Tanya-Solyanik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (OsVersion.IsWindows8OrGreater()) | ||
| { | ||
| foreach (DataGridViewRow row in Rows) | ||
| { | ||
| foreach (DataGridViewCell cell in row.Cells) | ||
| { | ||
| cell.ReleaseUiaProvider(); | ||
| } | ||
|
|
||
| row.HeaderCell.ReleaseUiaProvider(); | ||
| row.ReleaseUiaProvider(); | ||
| } | ||
|
|
||
| foreach (DataGridViewColumn column in Columns) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you unify argument in this method, please use |
||
| { | ||
| column.HeaderCell.ReleaseUiaProvider(); | ||
| } | ||
|
||
|
|
||
Tanya-Solyanik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _editingPanel?.ReleaseUiaProvider(IntPtr.Zero); | ||
| _editingPanelAccessibleObject = null; | ||
| _topLeftHeaderCell?.ReleaseUiaProvider(); | ||
|
|
||
| if (AccessibilityObject is DataGridViewAccessibleObject accessibleObject) | ||
| { | ||
| accessibleObject.ReleaseChildUiaProviders(); | ||
| } | ||
| } | ||
|
|
||
| base.ReleaseUiaProvider(handle); | ||
| } | ||
|
|
||
| private void RemoveIndividualReadOnlyCellsInColumn(int columnIndex) | ||
| { | ||
| int cellIndex = 0; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,8 +90,6 @@ public virtual bool RepositionEditingControlOnValueChange | |
| } | ||
| } | ||
|
|
||
| internal override bool SupportsUiaProviders => true; | ||
Tanya-Solyanik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public virtual void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(dataGridViewCellStyle); | ||
|
|
@@ -287,6 +285,16 @@ protected override bool ProcessKeyEventArgs(ref Message m) | |
| return base.ProcessKeyEventArgs(ref m); | ||
| } | ||
|
|
||
| internal override void ReleaseUiaProvider(nint handle) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion - consider unifying argument in this method to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes and don't use IntPtr.Zero as input
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it OK to provide 0 as the default value? I mean |
||
| { | ||
| if (TryGetAccessibilityObject(out AccessibleObject? accessibleObject)) | ||
| { | ||
| ((DataGridViewTextBoxEditingControlAccessibleObject)accessibleObject).ClearParent(); | ||
| } | ||
|
|
||
| base.ReleaseUiaProvider(handle); | ||
| } | ||
|
|
||
| private static HorizontalAlignment TranslateAlignment(DataGridViewContentAlignment align) | ||
| { | ||
| if ((align & AnyRight) != 0) | ||
|
|
@@ -306,10 +314,11 @@ private static HorizontalAlignment TranslateAlignment(DataGridViewContentAlignme | |
| protected override void OnHandleCreated(EventArgs e) | ||
| { | ||
| base.OnHandleCreated(e); | ||
| if (IsHandleCreated) | ||
|
|
||
| // The null-check was added as a fix for a https://github.com/dotnet/winforms/issues/2138 | ||
| if (IsHandleCreated && _dataGridView?.IsAccessibilityObjectCreated == true) | ||
| { | ||
| // The null-check was added as a fix for a https://github.com/dotnet/winforms/issues/2138 | ||
| _dataGridView?.SetAccessibleObjectParent(AccessibilityObject); | ||
| _dataGridView.SetAccessibleObjectParent(AccessibilityObject); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can also set
_topRowAccessibilityObjectand_selectedCellsAccessibilityObjectto null here, so that if it gets called twice there is no double disconnect.