PRB: COM Objects Created in JScript Not Released Immediately (164494)
The information in this article applies to:
- Microsoft Visual Basic, Scripting Edition 2.0
- Microsoft Visual Basic, Scripting Edition 3.0
- Microsoft Visual Basic, Scripting Edition 4.0
- Microsoft Visual Basic, Scripting Edition 5.0
- Microsoft JScript 2.0
- Microsoft JScript 3.0
- Microsoft JScript 4.0
- Microsoft JScript 5.0
This article was previously published under Q164494 SYMPTOMS
COM objects that were created in JScript may not be released immediately after their last reference in script is out of scope or set to null.
CAUSE
The Microsoft JScript engine uses deferred garbage collection to free unused objects. The garbage collector improves script engine performance by delaying object destruction until a more economical time.
RESOLUTION
If you develop objects that will be used in script, you should consider this behavior of the garbage collector when you design the objects. In those extreme situations when objects must have their resources cleaned on demand, Microsoft recommends that you add methods to the object to provide for this.
For example, an object that loads a large text file into memory could provide a CloseFile method to script to allow for the immediate release of the memory buffers that are used by the object. In this case, although the object is still held in memory until the garbage collector is ready to release it, the huge effect of the text file buffer is alleviated.
REFERENCES
For more information about VBScript and JScript, visit the following Microsoft Web site:
Modification Type: | Major | Last Reviewed: | 10/24/2003 |
---|
Keywords: | kbprb kbProgramming kbScript KB164494 |
---|
|