INFO: VBScript and JScript Do Not Release Host Dispatch Objects

Last reviewed: September 30, 1997
Article ID: Q164494
The information in this article applies to:
  • Microsoft Visual Basic, Scripting Edition, versions 1.0, 1.1
  • Microsoft JScript, version 1.0

SUMMARY

When hosting version 1.0 of VBScript or JScript using the ActiveX Scripting interfaces, dispatch objects are not released immediately by the scripting engine.

For example, in the following VBScript code the dispatch object for X is not be released when X is set to 0:

   Set X = HostObject.HostDispatchObject
   X = 0

MORE INFORMATION

The version 1.0 VBScript and JScript engines use a deferred garbage collection scheme to release dispatch object pointers. In the example above, X is freed eventually by the engine. Version 1.0 of VBScript and JScript free temporary objects and release dispatch pointers after 8192 temporary variants or 128K of strings have been allocated.

If necessary, the following line of VBScript forces an immediate garbage collection:

   Y = len(string(65537, 'x'))

This script line fills up a temporary string larger than 128K, which causes garbage collection to start. The temporary string is not stored; if it were, the string contents would not be freed until the aforementioned conditions are met and the next garbage collection is performed.

REFERENCES

For information on hosting VBScript or JScript in an application, refer to the ActiveX SDK documentation, which is available at the following Web site:

   http://www.microsoft.com/intdev/sdk

It is also available at the VBSCript and JScript Web sites:

   http://www.microsoft.com/vbscript
   http://www.microsoft.com/jscript
Keywords          : AXSDKSripting kbprg
Version           : 1.00 1.10
Platform          : WINDOWS


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.