Closed kirsan31 closed 1 month ago
@Olina-Zhang - could you please retest this issue?
@Olina-Zhang - could you please retest this issue?
Verified this issue in the latest .Net 8.0 build as above sample application and video in VS, have same testing result, so still repro.
Dispose has a section to dispose of the items. I guess we just do the same for the DisplayedItems
and OverflowItems
https://github.com/dotnet/winforms/blob/e199c86138cf8fee176bddd3f7e19ec62a526765/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs#L2011-L2020
We might also want to look at OnItemRemovedInternal
. Which is called by ToolStripItemCollection
when an item is removed (such as when ToolStripItem.Dispose
is called).
https://github.com/dotnet/winforms/blob/e199c86138cf8fee176bddd3f7e19ec62a526765/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs#L4906-L4909
We could then trigger a cleanup DisplayedItems
and OverflowItems
, I think ToolStripItemCollection
might need to pass itself to OnItemRemovedInternal
so we can cleanup based on which list had the item removed.
Verified this issue in the latest .Net 9.0 RC2 SDK build: 9.0.100-rc.2.24468.2 + binaries built fromWinforms repo main branch, it was fixed.
https://github.com/user-attachments/assets/4eab15ae-d2d4-48e3-9e88-a772b698b30d
.NET Core Version: all up to latest (5.0.5)
Have you experienced this same bug with .NET Framework?: Yes
Problem description:
ToolStripMenuItem
can lead to memory leaks in some special conditions.private void windowsToolStripMenuItem_DropDownClosed(object sender, EventArgs e) { while (listToolStripMenuItem.DropDownItems.Count > 0) listToolStripMenuItem.DropDownItems[listToolStripMenuItem.DropDownItems.Count - 1].Dispose(); }