-
Notifications
You must be signed in to change notification settings - Fork 986
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
DetachContextMenuStrip pattern can lead to memory leaks #12353
Comments
@LeafShi1 can your team please test this? |
|
The funniest thing is that this whole story with Disposed event was invented so that the user would not do intuitively understandable things like nullout |
Yea, or null out |
@elachlan @JeremyKuhne What do you think about this issue? |
A user is responsible for the lifespan of a control they create. But in this case, we aren't asking for the user to dispose of the |
For For existing code, we need to be careful that we don't dispose something that we've created that user's code might have a reference to. |
@JeremyKuhne what do you think about implementing this |
@kirsan31 I'm not opposed in general. If someone wants to do this I'll entertain it, but be forewarned that I don't have a lot of bandwidth at the moment. :) Things I would want to see:
|
I read this topic, so I suggested implementing it in a narrow specific case, where we can avoid problems of wide public implementation. |
@kirsan31 I believe we should encapsulate what we do here. I pointed out the issue not to say that we need to solve it, just that we need to consider and reference it so that:
Our helper doesn't need to solve all things, just the immediate need. |
.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
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Line 1232 in d198602
ContextMenuStrip.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
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewBand.cs
Line 59 in 1f2d238
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewCell.cs
Line 117 in 1f2d238
My thots are:
ContextMenuStrip.Disposed -= disposedHandler;
code inControl.Dispose
.Steps to reproduce
DetachContextMenuStripLeaks.zip
DataGridView
elements.Control
class.The text was updated successfully, but these errors were encountered: