Microsoft KB Archive/873429

= FIX: A gradual memory leak occurs in a WinForm application when you create, modify, or remove a MenuItem property for an MDI form in the .NET Framework 1.1 =

Article ID: 873429

Article Last Modified on 4/7/2006

-

APPLIES TO


 * Microsoft .NET Framework 1.1

-





SYMPTOMS
When you create, modify, or remove a MenuItem property for a Multiple Document Interface (MDI) form in Microsoft .NET Framework 1.1 Service Pack 1 (SP1), a GDI resource leak occurs, and there is gradual increase in the application memory usage. This problem occurs when you create a WinForm application that uses an MDI form.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft .NET Framework 1.1 service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel. Date        Time   Version            Size    File name --- 23-Jul-2004 15:36  1.1.4322.1064   1,703,936  System.design.dll 23-Jul-2004 15:29  1.1.4322.1064     466,944  System.drawing.dll 23-Jul-2004 15:36  1.1.4322.1064   2,043,904  System.windows.forms.dll



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
  Create a Visual Basic .NET MDI Form by using the following code. Private Sub frmStart_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

Menu = MenuMainSetup

End Sub

Public Function MenuMainSetup As MainMenu

' Set up main menu with 1 item (Member) and two subitems (Open and Close Member)

Dim mnuMain As New MainMenu

Dim mitAdd As New MenuItem(&quot;Member&quot;)

mitAdd.MergeType = MenuMerge.MergeItems

mitAdd.MergeOrder = 1

Dim i As Integer = mnuMain.MenuItems.Add(mitAdd)

mitAdd = New MenuItem(&quot;Open&quot;, New EventHandler(AddressOf zOpenChild))

mitAdd.MergeType = MenuMerge.MergeItems

mitAdd.MergeOrder = 1

mnuMain.MenuItems(i).MenuItems.Add(mitAdd)

mitAdd = New MenuItem(&quot;Close Member&quot;)

mitAdd.MergeType = MenuMerge.MergeItems

mitAdd.Visible = False

mitAdd.MergeOrder = 2

mnuMain.MenuItems(i).MenuItems.Add(mitAdd)

mitAdd = New MenuItem(&quot;Test GC&quot;, New EventHandler(AddressOf Test))

mitAdd.MergeType = MenuMerge.MergeItems

mitAdd.MergeOrder = 3

mnuMain.MenuItems(i).MenuItems.Add(mitAdd)

Return mnuMain

End Function

Public Function MenuSubSetup As MainMenu

' Set up additional History menu item to go in Member menu

Dim mnuMain As New MainMenu

Dim mitAdd As New MenuItem(&quot;Member&quot;)

mitAdd.MergeType = MenuMerge.MergeItems

mitAdd.MergeOrder = 1

Dim i As Integer = mnuMain.MenuItems.Add(mitAdd)

mitAdd = New MenuItem(&quot;History&quot;)

mitAdd.MergeType = MenuMerge.MergeItems

mitAdd.MergeOrder = 4

mnuMain.MenuItems(i).MenuItems.Add(mitAdd)

mitAdd = Nothing

Return mnuMain

End Function

Private Sub zOpenChild(ByVal sender As System.Object, ByVal e As System.EventArgs)

' Open our only child

Dim f As New frmMemLeak

f.MdiParent = Me

f.Show

End Sub

Private Sub Test(ByVal sender As System.Object, ByVal e As System.EventArgs)

GC.Collect

GC.WaitForPendingFinalizers

End Sub   Create a Windows Form by using the following code. Region &quot; Windows Form Designer generated code &quot;

Public Class frmMemLeak : Inherits System.Windows.Forms.Form


 * 1) Region &quot; Windows Form Designer generated code &quot;

Public Sub New

MyBase.New

'This call is required by the Windows Form Designer.

InitializeComponent

'Add any initialization after the InitializeComponent call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose

End If End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Private WithEvents cmdClose As System.Windows.Forms.Button



Private Sub InitializeComponent

Me.cmdClose = New System.Windows.Forms.Button

Me.SuspendLayout

'

'cmdClose

'

Me.cmdClose.Location = New System.Drawing.Point(16, 16)

Me.cmdClose.Name = &quot;cmdClose&quot;

Me.cmdClose.TabIndex = 5

Me.cmdClose.Text = &quot;Close&quot;

'

'frmMemLeak

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(104, 61)

Me.Controls.Add(Me.cmdClose)

Me.Name = &quot;frmMemLeak&quot;

Me.Text = &quot;Leak&quot;

Me.ResumeLayout(False)

End Sub


 * 1) End Region

Private Sub frmMemLeak_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' Disable the Close Member menu item

MdiParent.Menu.MenuItems(0).MenuItems(1).Enabled = False

End Sub

Private Sub frmMemLeak_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

' Add the History menu item to the Member menu

Menu = CType(MdiParent, frmStart).MenuSubSetup

End Sub

Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click

MdiParent.Menu.MenuItems(0).MenuItems(1).Enabled = True

Me.Close

End Sub

End Class  Run the application. In the application, click Member, and then click Open. In the application, click Member, and then click Test GC.</li> Repeat steps 4 and 5 several times to create the leak.</li></ol>

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

Keywords: kbbug kbfix kbqfe kbhotfixserver KB873429

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.