memory problems

I have a main window in my project, and numerous other child widows inside the main.
 When I open the one child  main window occupies some memory, i can see it in task manager.
 When I close the  child window the occupied memory is not released.
I used:
Private Sub MainForm_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
end sub

But this is not works.
Please can anyone give me some idea how to resolve this.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pramod BugudaiCommented:
Hi. Instead of using Me.Dispose, why don't you use Me.Close(). This is a best way to do over Dispose().
I would declare an event in a common place such as a module

Private Sub Form_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
     Sender = Nothing
End Sub

Then wherever I declare a form,

Dim f as new someform
AddHandler f.FormClosed, AddressOf Form_FormClosed

mastiSoftAuthor Commented:
if I use Me.Close then I get:An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll.
this is MDI application and I need to clean memory when child form close.

to load a new form I use
                    AktivForm = New MainForm
                    'New Form Creater & Show
                    AktivForm.MdiParent = Me

                    'AktivForm.Tag = m_ChildFormNumber
                    AktivForm.Text = My.Computer.FileSystem.GetName(OpenFileName)

This is from MDIParent.
Then when a child form close  then i use  Private Sub MainForm_FormClosed(...
Where I have to use your suggestion mr.CodeCruiser

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

>Where I have to use your suggestion mr.CodeCruiser

>Then when a child form close  then i use  Private Sub MainForm_FormClosed(...

Why would you call Close on a form which is already closing???

GC.Collect removes objects that have no more references left. When you call it from within the form, the form is still being referenced. Call GC.Collect from the calling location which is MDI form. As I have shown, use an event handler on the mdi form which handles the closing event of ALL child forms. Then call GC.Collect in that event handler.
mastiSoftAuthor Commented:
I add the module as you suggested.
and line AddHandler f.FormClosed, AddressOf Form_FormClosed before show child form.
Nothing change,
Why I need this:
Before opening the child form  Task Manager show that the application use let say 6000 k
When child form opens this value increase to  9000 k. If I close this form then it still 9000k.
Opening several files(forms) this amount just be bigger and at the some moment application just hangs.
>Why I need this

To remove the reference of the form.

Show us the relevant complete code that you have now.
Microsoft .NET uses Garbage Collector to release unused memory. Usually there is no need for developers to explicitly release memory. .NET Framework calls GC.Collect() on specific times to release memory.
When something like your situation happens, it shows that you have a memory leak.
Perhaps you keep a reference to your forms after they close.
For example if your child form subscribes to an event of your parent form, your parent form has a hidden reference to the child form. So when you close the child form, the occupied memory will no release.

There are some tools that help you find memory leaks.
Sci Tech .NET Memory Profiler ( is a very good one that I used before. You can use it to find your memory leak. Feel free to ask me your questions about that.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.