im creating just a simple MDI app and to add a child window i use this code..

Dim NewMDIChild As New Form2()
NewMDIChild.MdiParent = Me
NewMDIChild.Show()

and it worked, but after a bit i got an error

An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll

Additional information: Error creating window handle.


Now im guessing i am not freeing up my childs after i create and close them, because of the OutOfMemoryException part.

If this is the case, how do i free them when the app closes?


P.S Side question
I would like
Dim NewMDIChild As New Form2()
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
in a module, but if i change the

newmdichild.mdiparent = me to
newmdichild.mdiparent = Form2

it doesnt work, how can i do this?

thanks