When must I set a variable to “Nothing” in VB6?

后端 未结 8 3293
刺人心
刺人心 2021-02-20 19:00

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...
Se         


        
8条回答
  •  忘掉有多难
    2021-02-20 19:18

    @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.

    Private Sub Form_Load()
      Dim frm As Form2
      Set frm = New Form2
      frm.Show
      Set frm = Nothing
    End Sub
    

    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.

    Unload Forms(1)
    

    Am I seeing the problem correctly?

    • Josh

提交回复
热议问题