Alex Rivera | Logout

When must I set a variable to "Nothing" in VB6?

Asked 2008-08-27T14:54:52.423
10

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.

Edit
Report

1 Answer

4

@Martin

VB6 had a "With/End With" statement that worked "like" the Using() statement in C#.NET. And of course, the less global things you have, the better for you.

With/End With does not working like the Using statement, it doesn't "Dispose" at the end of the statement.

With/End With works in VB 6 just like it does in VB.Net, it is basically a way to shortcut object properties/methods call. e.g.

With aCustomer
  .FirstName = "John"
  .LastName = "Smith"
End With
answered 2008-08-27T15:11:41.993

Your Answer