Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does MdiChild Close remove Reference in MdiParent?

Status
Not open for further replies.

SprintFlunky

Programmer
Apr 6, 2004
51
US
Simple question but I must not be doing something right.

In Form1:
Dim F2 as new Form2
f2.MdiParent = Me
f2.Show

In Form2:
Me.Close()

If I then loop through the MdiChilden of Form1, f2 is still referenced and if I do a .Show() it will show back up.

How do I destroy f2 in the Form1 class?
 
Try f2.dispose

See if that works. Close won't remove the reference until the garbage collector comes around.
 
Dispose actually triggers with a close event and does not remove the reference from Form1. However, after a little more looking around, I found a soultion that works:

in Form1:

If not f2 is Nothing then
f2.Close
f2 = Nothing
End if
Dim f2 as new Form2
..

This allows me to put logic in Form2.Close to perform any wrap up logic before creating a new f2. Not the best looking code, but it should stop memory leaks.

Thanks for the reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top