我一直在使用SWF-ToolStrip时遇到内存泄漏的问题。根据这个链接,这个问题已经被解决了。但是在这里似乎还没有。
有人知道如何解决这个问题吗?
protected override void Dispose(bool disposing)
{
if (disposing)
{
var overflow = toolStrip1.OverflowButton.DropDown as ToolStripOverflow;
if (overflow != null)
overflow.Dispose();
}
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
私有子 frmBase_FormClosed(ByVal 作为对象 ByVal 发送者, ByVal e 作为 System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
' .NET BUG WORKAROUND
' MANUALLY DISPOSE OF ToolStip, MenuStrip and StatusStrip to release memory being held
Dim aNames As New ArrayList
Dim count As Integer = 0
For Each oItem As ToolStripItem In Me.MenuStrip1.Items
aNames.Add(oItem.Name)
Next
For i As Integer = 0 To aNames.Count - 1
For Each oItem As ToolStripItem In Me.MenuStrip1.Items
If oItem.Name = aNames(i) Then
oItem.Dispose()
Exit For
End If
Next
Next
count = 0
aNames.Clear()
For Each oItem As ToolStripItem In Me.ToolStrip1.Items
aNames.Add(oItem.Name)
Next
For i As Integer = 0 To aNames.Count - 1
For Each oItem As ToolStripItem In Me.ToolStrip1.Items
If oItem.Name = aNames(i) Then
oItem.Dispose()
Exit For
End If
Next
Next
count = 0
aNames.Clear()
For Each oItem As ToolStripItem In Me.StatusStrip1.Items
aNames.Add(oItem.Name)
Next
For i As Integer = 0 To aNames.Count - 1
For Each oItem As ToolStripItem In Me.StatusStrip1.Items
If oItem.Name = aNames(i) Then
oItem.Dispose()
Exit For
End If
Next
Next
Me.MenuStrip1.Dispose()
Me.ToolStrip1.Dispose()
Me.StatusStrip1.Dispose()
End Sub