Urgent: MDI Windows form Memory Leak: Major Issue

G

Guest

Hey guys,

We have, a windows form application in VB.NET.

The way this application is structured is, there’s a MasterForm which
contains a Main menu and acts as the mdi parent to around 20 windows forms.
We have a BaseForm with some controls on it inherited by 20 other forms.

The problem we are facing is, as we work on the application, as new
instances of the forms are created, the memory used by the application keep
on increasing (Memory leak happens).

We have even run QTP scripts and observed the Memory usage on TaskBar. It
just keeps on increasing consistently.

On some of the forms we have like around 30 labels and equal number of
textboxes, with datagrid.
Here’s the code being used to display a form and close the present one:

Dim lForm As System.Windows.Forms.Form

‘The type associated with that particular form is returned from the main
assembly (windows application)
Dim lType As Type = AssemblyHelper.FindType(formName)
Try
If Not lType Is Nothing Then
lForm = CType(Activator.CreateInstance(lType),
System.Windows.Forms.Form)
lForm.MdiParent = Me.MdiParent
lForm.Show()
Me.Close()
End If
Catch ex As Exception
Throw ex
End Try

My questions are:

1. Is it a known issue with .NET framework 1.1 SP1?

2. Is there a way to overcome the memory leak occurring?

3. When a form gets disposed, all the objects created including controls, do
they get disposed as well?

I have searched google groups and MSDN groups and found so many interesting
articles, but couldn’t find a solution to the problem.

Any help or suggestion is highly appreciated.

Thanks,

Vinay Kant
 
R

rampabbaraju

It could be that even if you call Me.Close(), it is not able to close
due to the new form that got created. Try not setting lForm.MdiParent
= Me.MdiParent. As far as I know, both the forms should get closed.

Try to raise an event from the first child, handle it in MdiParent, In
that handler create your second mdi child. That may solve your problem.
 
G

Guest

I tried that as well. Didn't work.
Funny thing is when i open a form as dialog using
Dim lFOrm as new PrintFax
lFOrm.ShowDialog()

Memory increases and is released, once the form is closed.

Also, we have been creating forms from masterform using menu bar with code:
Dim lForm As System.Windows.Forms.Form
Dim lType As Type = AssemblyHelper.FindType(formName)
If Not lType Is Nothing Then
lForm = CType(Activator.CreateInstance(lType), System.Windows.Forms.Form)
lForm.MdiParent = Me
Me.ActiveMdiChild.Refresh()
Me.ActiveMdiChild().Close()
lForm.Show()
End If

Nothing worked.

Any one with any other suggestion.

I have one more question, once form closes then all the objects created
within that form are also disposed right. The objects could be of controls,
custom classes.

Thanks,
 
R

rampabbaraju

Your assumption is correct. When a form closes, all the controls in the
form are disposed / will be garbage collected.

This could be the answer for your first question too. Second child form
is created from the first child. When first child form is closed,
second child form also should get disposed. Because you are setting the
main form as the parent of second child, garbage collector may not be
able to collect the first form memory also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top