开发者

Does a VB6 class have a destructor?

When I execute a statement such as

Set MyObject = Nothing

is there a particular function inside the class that is invoked (i.e. that I can use as a destructor), to do things like clean up arrays, disconnect开发者_StackOverflow from databases, and so forth?


Analogous to Class_Initialize, the constructor, there's 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 variables that reference this object have gone out of scope or have been set to set to something else (e.g. Nothing). Thus, Set MyObject = Nothing will only call the destructor if MyObject is the last variable referencing this object.


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

UPDATE:

One can use the Class_Terminate to handle this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜