Does VB6 class have a destructor?

When I execute a statement like

Set MyObject = Nothing 

Is there a specific function inside the called class (i.e., I can use it as a destructor) to do things like clearing arrays, disconnecting from databases, etc.?

+7
source share
2 answers

Like the Class_Initialize constructor, there is also a destructor:

 Sub Class_Terminate ... ' Put your destructor code here ' End Sub 

This method is executed as soon as the reference count of this object reaches zero, i.e. when all the variables that reference this object are out of scope or have been configured for something else (for example, Nothing ). Thus, Set MyObject = Nothing will only call the destructor if MyObject is the last variable referencing this object.

+16
source

Not. VB6 does not provide any mechanism for the programmer to write something explicitly. What a programmer can do is Set MyObject = Nothing , and VB will take care of the rest.

UPDATE:

You can use Class_Terminate to handle this.

-one
source

All Articles