Open kirsan31 opened 4 days ago
@LeafShi1 can your team please test this?
@elachlan DataGridView case (point 2) was tested in #6859. I will adapt repro app to test also point 1...
---------------------UPD---------------------
Updated 1 post with repro app and instructions.
.NET version
All up to .Net9.
Did it work in .NET Framework?
No
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No.
Issue description
This null out
ContextMenuStrip
pattern:Can lead to memory leaks. Using in 3 places:
Control
https://github.com/dotnet/winforms/blob/d1986025b2dafdcc3aeda0505da37e580bb3d82e/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs#L1232 More or less justified, since control in most cases lives either as long as the menu, or longer. But I didn't find aContextMenuStrip.Disposed -= disposedHandler;
code inControl.Dispose
. So ifContextMenuStrip
will outlive control (and user not null outContextMenuStrip
property) - we will have memory leak (control will remain in memory) at any case.DataGridViewBand
andDataGridViewCell
https://github.com/dotnet/winforms/blob/1f2d238fe75b40408de8d3cd6ca363df3615132f/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewBand.cs#L59 https://github.com/dotnet/winforms/blob/1f2d238fe75b40408de8d3cd6ca363df3615132f/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewCell.cs#L117 Here it probably does more harm than good, since DataGridView elements in most cases live less than the menu and they never disposed.My thots are:
ContextMenuStrip.Disposed -= disposedHandler;
code inControl.Dispose
.Steps to reproduce
DetachContextMenuStripLeaks.zip
DataGridView
elements.Control
class.