In one of my VB6 forms, I create several other Form objects and store them in member variables.
Private m_frm1 as MyForm Private m_frm2 as MyForm // Later... Set m_frm1 = New MyForm Set m_frm2 = New MyForm
I notice that I’m leaking memory whenever this (parent) form is created and destroyed. Is it necessary for me to assign these member variables to Nothing in Form_Unload()?
In general, when is that required?
SOLVED: This particular memory leak was fixed when I did an Unload on the forms in question, not when I set the form to Nothing. I managed to remove a few other memory leaks by explicitly setting some instances of Class Modules to Nothing, as well.
@Matt Dillard – Did setting these to nothing fix your memory leak?
VB6 doesn’t have a formal garbage collector, more along the lines of what @Konrad Rudolph said.
Actually calling unload on your forms seems to me to be the best way to ensure that the main form is cleaned up and that each subform cleans up their actions.
I tested this with a blank project and two blank forms.
After running both forms are left visible. setting frm to nothing did well… nothing.
After settign frm to nothing, the only handle open to this form is via the reference.
Am I seeing the problem correctly?