Simple Code for .net - Best way to close child form

i have an MDI application with multiple child do i close any open child forms so that only one child form is open at a time...
Who is Participating?
gopinathdeepakConnect With a Mentor Commented:
i presume u mean memory leaks....

if u have child forms on and off all the time....meaning u create and destroy them all the time, u might want to use the Form.Hide function istead of Close....because that way the form stays in memory and theres no question of de-allocating and re-allocating also makes the application faster..

if u go the other way, u may find (as i did in one of my apps) that the memory of the previous object (which u disposed by useing Form.Close) is not released by the app sometimes giving the impression that the application is hogging the memory...

so in MDI apps, in my opinion Form.Hide if judiciously used can perform better....

try this code...
assuming MDIParentForm1 to be an instance of the parent form in your mdi application,

dim i as integer = 0

for i=0 to MDIParentForm1.MdiChildren.GetLength(0)

dim child1 as new childform1()
child1.MDIParent = MDIParentForm1
xrokAuthor Commented:
how well does the Close function release the form object? i have critical memory management issues in my application..
Eduard GherguLeader SibiuCommented:
Unfortunatelly, there is no Forms collection in VB.NET... So, you have to create your own collection. You'll find an example at:
xrokAuthor Commented:
i was afraid of that.  I will use hide instead.  ty
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.

All Courses

From novice to tech pro — start learning today.