Skip to content

Commit

Permalink
Issue 12353 fix detach context menu strip memory leak (dotnet#12399)
Browse files Browse the repository at this point in the history
* Removing reference to ContextMenuStrip when dispose control

* Merge 'main' to current branch

* Detach ContextMenuStrip from control when executing Dispose

* Use pattern matching for judge variable menu
  • Loading branch information
LeafShi1 authored and paul1956 committed Nov 5, 2024
1 parent 456fe40 commit c67ba0b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4694,6 +4694,12 @@ protected override void Dispose(bool disposing)
}
}

// Unsubscribes from the Disposed event of the ContextMenuStrip.
if (ContextMenuStrip is ContextMenuStrip menu)
{
menu.Disposed -= DetachContextMenuStrip;
}

ReflectParent = null;

if (disposing)
Expand Down

0 comments on commit c67ba0b

Please sign in to comment.