I have developed a .Net app in MDI format. The problem that I have is that every time I change screens (New Child), the PC CPU PageFile usage increments a little. This happens until out of memory and I get a System.OutOfMemoryException.
Is there something subtle Im missing when opening/closing MDIChild forms?
I have written a sub to check that only 1 child is open at 1 time and close all child forms, before opening another:
Expand|Select|Wrap|Line Numbers
- Public Sub CloseForms()
- Dim frm As Form
- Dim Count As Integer
- For Each frm In MDIParent1.MdiChildren
- Count = Count + 1
- frm.Dispose()
- Next
- frm = Nothing
- Count = Nothing
- End Sub
System.GC.Collect()
I also wrote a sub to dispose of all controls on each screen every time a form closes:
Expand|Select|Wrap|Line Numbers
- Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- Dim FormObject As Control
- For Each FormObject In Me.Controls
- FormObject.Dispose()
- Next
- End Sub