javascript| Tutorial
Using OLE Automation in JavaScript
6. How to improve the performance of the script program
Since we are dealing with heavy object models (such as Word.Application) and application instances, it is important to note that the system's resources are shown. Once we have finished processing the application instance, we have to remove it to erase the object's instance from memory. There is only one way to implement it in JScript, which is the Quit () method of the Application object, and here's an example:
var wdapp = new ActiveXObject ("Word.Application");
Wdapp.quit (); Tidy up
In Visual Basic, unlike JScript and VBScript, setting an object variable to null does not erase memory. Also, if there are no other references to this object, such an assignment will cause the application to shut down. Unfortunately, in JScript we have to use the Quit () method to clear the object from memory when we have already used it. Setting a variable to a zero-length string or being empty is just a good exercise, and it does not erase memory.
Place a point at least code in the tutorial a procedure call has to be executed in the background. The best solution is to localize the cache object reference. In a nutshell, this technique can be applied to objects as well as automation objects. Here's a look at the script fragment:
var Exapp = new ActiveXObject ("Excel.Application");
Exapp.workbooks (1). Worksheets (1). Cells (1, 1). Value = "A-Cell";
Exapp.workbooks (1). Worksheets (1). Cells (1, 2). Value = "Second Cell";
Exapp.workbooks (1). Worksheets (1). Cells (1, 3). Value = "Third Cell";
Exapp.workbooks (1). Worksheets (1). Cells (1, 4). Value = "Fourth Cell";
Exapp.workbooks (1). Worksheets (1). Cells (1, 5). Value = "Fifth Cell";
The following code illustrates a more efficient way to implement:
var Exapp = new ActiveXObject ("Excel.Application");
var exwbook = exapp.workbooks (1). Worksheets (1);
Exwbook.cells (1, 1). Value = "A-Cell";
Exwbook.cells (1, 2). Value = "Second Cell";
Exwbook.cells (1, 3). Value = "Third Cell";
Exwbook.cells (1, 4). Value = "Fourth Cell";
Exwbook.cells (1, 5). Value = "Fifth Cell";