-
Notifications
You must be signed in to change notification settings - Fork 992
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
ToolStripMenuItem can lead to memory leaks #4808
Comments
@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 winforms/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs Lines 2011 to 2020 in e199c86
|
We might also want to look at winforms/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs Lines 4906 to 4909 in e199c86
We could then trigger a cleanup |
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. GHIssue4808Verify.mp4 |
.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.In certain conditions (I think that is - open only main menu and not opening submenu
listToolStripMenuItem
) after closing main menu some oflistToolStripMenuItem
subitems will remain in memory. See video below.This happens due to
_displayedItems
collection still have live references to removed menu items. I think this collection ( and may be_overflowItems
too ) must be checked on item removal.menu.mp4
Workaround:
You can call
listToolStripMenuItem.DropDown.PerformLayout();
after items removal. This lead to call ofSetDisplayedItems()
which will clear_displayedItems
of removed elements.Expected behavior:
All removed and disposed menu elements must be eligible to GC (have no live references).
Minimal repro:
WinFormsCoreTest_Grid_Menu.zip
The text was updated successfully, but these errors were encountered: