winforms
winforms copied to clipboard
Control classes leaking memory
.NET version
.NET 7.0 Preview 4
Did it work in .NET Framework?
No
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
Investigating possible memory leaks with Windows Forms classes inherited to Control class AND in corresponding Accessible Objects. Some control items and some accessible objects are left in memory after the control instance with its items was inspected with accessibility tool (like Accessibility Insights or Inspect) and the form with the control is closed, garbage is collected, but accessibility tool is still opened.
Abstract, private and internal control classes which can't be placed in a form Controls collection are not applicable. Control classes from the namespace System.Windows.Forms.Design are not not applicable.
Table 1. Control classes tested for memory leaks:
Class name | Base class name | Memory leaks | Issue assigned | Status |
---|---|---|---|---|
DataGridView | Control | Is leaking | #7347 | Waiting for review |
PropertyGrid | ContainerControl | Is leaking | #6943 | Work in progress |
DomainUpDown | UpDownBase | Is leaking | #7328 | Fixed |
ToolStrip | ScrollableControl | Is leaking | #7375 | Fixed |
ListBox | ListControl | Is leaking | #7197 | Fixed |
ListView | Control | Is leaking | #7385 | Fixed |
CheckedListBox | ListBox | Is leaking | #7197 | Fixed |
ComboBox | ListControl | Is leaking | #7318 | Fixed |
TextBox | TextBoxBase | Is leaking | #7248 | Work in progress |
TreeView | Control | Is leaking | #7196 | Fixed |
MonthCalendar | Control | Is leaking | #6852 | Fixed |
NumericUpDown | UpDownBase | Is leaking | #7328 | Fixed |
TabPage | Panel | Is leaking (when tested with Narrator) | #7415 | Fixed |
Button | ButtonBase | Is not leaking | ||
CheckBox | ButtonBase | Is not leaking | ||
RadioButton | ButtonBase | Is not leaking | ||
DateTimePicker | Control | Is not leaking | ||
GroupBox | Control | Is not leaking | ||
ThreadExceptionDialog | Form | Is not leaking | ||
UpDownBase | ContainerControl | Is not leaking | ||
SplitterPanel | Panel | Is not leaking | ||
BindingNavigator | ToolStrip | Is not leaking | ||
MenuStrip | ToolStrip | Is not leaking | ||
StatusStrip | ToolStrip | Is not leaking | ||
ContextMenuStrip | ToolStripDropDownMenu | Is not leaking | ||
ToolStripOverflow | ToolStripDropDown | Is not leaking | ||
HScrollBar | ScrollBar | Is not leaking | ||
VScrollBar | ScrollBar | Is not leaking | ||
Label | Control | Is not leaking | ||
LinkLabel | Label | Is not leaking | ||
ProgressBar | Control | Is not leaking | ||
RichTextBox | TextBoxBase | Is not leaking | ||
MaskedTextBox | TextBoxBase | Is not leaking | ||
TabControl | Control | Is not leaking | ||
TrackBar | Control | Is not leaking | ||
DataGridViewTextBoxEditingControl | TextBox | Is not leaking | ||
PrintPreviewControl | Control | Is not leaking | ||
ToolStripPanel | ContainerControl | Is not leaking | ||
SplitContainer | ContainerControl | Is not leaking | ||
ToolStripContainer | ContainerControl | Is not leaking | ||
Panel | ScrollableControl | Is not leaking | ||
TableLayoutPanel | Panel | Is not leaking | ||
ToolStripContentPanel | Panel | Is not leaking | ||
DataGridViewComboBoxEditingControl | ComboBox | Is not leaking | ||
PictureBox | Control | Is not leaking | ||
ColorEditorTabControl | TabControl | Is not leaking | ||
Splitter | Control | Is not leaking | ||
WebBrowser | WebBrowserBase | Is not leaking | Deprecated |
Table 2. Control classes that are not applicable on the form:
Class name | Base class name |
---|---|
Control | |
AdornerWindow | Control |
AnchorUI | Control |
AxHost | Control |
ButtonBase | Control |
DetailsButton | Button |
DropDownButton | Button |
EditorButton | Button |
SplitButton | Button |
DockEditorCheckBox | CheckBox |
ColorPalette | Control |
ColorUI | Control |
ContainerPlaceholder | Control |
ContentUI | Control |
ControlPlaceholder | Control |
DateTimeUI | Control |
DesignerFrame | Control |
DockUI | Control |
GridToolTip | Control |
SelectionUIService | Control |
ScrollableControl | Control |
ComponentTray | ScrollableControl |
ContainerControl | ScrollableControl |
DesignerActionPanel | ContainerControl |
BinaryUI | Form |
CollectionForm | Form |
CollectionEditorCollectionForm | CollectionForm |
StringCollectionForm | CollectionForm |
ComponentEditorForm | Form |
DataGridViewCellStyleBuilder | Form |
DropDownHolder | Form |
FormatStringDialog | Form |
FlyoutDialog | Form |
DropDownHolder | FlyoutDialog |
GridErrorDialog | Form |
PrintPreviewDialog | Form |
StatusDialog | Form |
LinkAreaUI | Form |
MaskDesignerDialog | Form |
MdiWindowDialog | Form |
ParkingWindow | ContainerControl |
ToolStripNumericUpDownControl | NumericUpDown |
UserControl | ContainerControl |
BorderSidesEditorUI | UserControl |
FormatControl | UserControl |
ShortcutKeysUI | UserControl |
MaskedTextBoxTextEditorDropDown | UserControl |
OverlayControl | ScrollableControl |
ComponentEditorPage | Panel |
DataGridViewEditingPanel | Panel |
FlowLayoutPanel | Panel |
ByteViewer | TableLayoutPanel |
ToolStripEditorControl | Panel |
PropertyGridToolStrip | ToolStrip |
MdiControlStrip | MenuStrip |
MdiWindowListStrip | MenuStrip |
ToolStripDropDown | ToolStrip |
DesignerActionToolStripDropDown | ToolStripDropDown |
FeedbackDropDown | ToolStripDropDown |
ToolStripDropDownMenu | ToolStripDropDown |
GroupedContextMenuStrip | ContextMenuStrip |
BaseContextMenuStrip | GroupedContextMenuStrip |
NewItemsContextMenuStrip | GroupedContextMenuStrip |
TransparentToolStrip | ToolStrip |
ScrollBar | Control |
SKWindow | Control |
SpringControl | Control |
EditorLabel | Label |
MethodItemLinkLabel | LinkLabel |
StickyLabel | Label |
ListControl | Control |
ColorEditorListBox | ListBox |
CursorUI | ListBox |
GridViewListBox | ListBox |
FilterListBox | ListBox |
ToolStripComboBoxControl | ComboBox |
MarshalingControl | Control |
MdiClient | Control |
DateTimeMonthCalendar | MonthCalendar |
RightToLeftLayoutGrip | Control |
ToolStripProgressBarControl | ProgressBar |
PropertyGridView | Control |
SnappableControl | Control |
CommandsPane | PropertyGrid.SnappableControl |
HelpPane | PropertyGrid.SnappableControl |
TabOrder | Control |
TextBoxBase | Control |
MultilineStringEditorUI | RichTextBox |
ridViewTextBox | TextBox |
mplateTextBox | TextBox |
ToolStripTextBoxControl | TextBox |
UpDownEdit | TextBox |
ToolStripAdornerWindow | Control |
TrayControl | Control |
PageSelector | TreeView |
Selector | TreeView |
UpDownButtons | Control |
WebBrowserBase | Control |
Steps to reproduce
- Include a MemoryLeaks_Form to WinformsControlsTest (impemented in https://github.com/dkazennov/winforms/tree/MemoryLeaks_Form).
- Test each form with WinDbg and Inspect.
The separate application to test memory leaks (it uses checkbox instead of buttons to switch between the forms to isolate the Button tested class memory objects): MemoryLeaksApp.zip
To confirm - are controls leaking memory, or their AO implementations?
To confirm - are controls leaking memory, or their AO implementations?
There are problems both with Controls and Accessible objects. This issue is to investigate the whole problem and to create subsequent issues.
- [ ] Button control:
- [ ] CheckBox control:
- [ ] DataGridView control:
- [ ] ListView:
- [ ] RichTextBox:
- [ ] MaskexTextBox:
- [ ] CheckedListBox:
- [ ] Panel:
- [ ] WebBrowser:
ToolStrip:
TabPage leaks when tested with Narrator:
I tested the Button control class in a standalone application without buttons to switch between forms (checkboxes are being used instead). If there are no buttons in the application (only the Button to test the control class), then there will be no Button class object and Button.AccessibleObject class object in the Heap after the manual garbage collection.
Retested controls - found no leaks:
- ListView
- RichTextBox
- MaskedTextBox
- [ ] ListView:
- [ ] RichTextBox:
- [ ] MaskedTextBox:
I found that ListView does have a leak, if testing with Narrator or not refreshing tree in Inspect. Will be tracked in #7385.
This issue was addressed in https://github.com/dotnet/winforms/issues/9224