In what order are objects in a .vbs destroyed?
That is, given these globals:
Set x = New Xxx
Set y = New Yyy
I'm interested in answers to any of the following.
For instances of classes implemented in the .VBS, in what order will
Class_Terminate
be called? Cursory poking suggests in the order (not reverse order!) of creation, but is this guaranteed?EDIT: I understand that
Class_Terminate
will be called when the last last reference to an object is released. What I meant was: in what order will x and y be released, and is it guaranteed? Assume for simplicity that x & y are the only references to their respective objects.Does the type of object matter? e.g. if I have classes implemented in the .VBS mixed in with other COM objects such as
Scripting.FileSystemObject
.EDIT: I understand that a COM library may set up its own internal circular references that the script host engine knows nothing about; I'm interested in exploring what could affect the answer to the first question.
Are the answers to the above different if x and y were local to a Sub or Function rather than global?
Does it depend on whether the exit is normal, by exception, or via
WScript.Quit
? (In the latter case, it seems thatClass_Terminate
is still called on any outstanding objects before exiting, however these may cause an error to be reported).When is the WScript object destroyed?
Does the script host matter? (wscript.exe vs cscript.exe vs. whatever the web host engine is called)
Does JScript's object destruction model differ to VBScript's?
I can find the answers to some of these questions empirically, but I'm interested in whether any of them are guaranteed / documented.
Do post even if you only know some of the answers - or further relevant issues.