Doing some research in the hope of finding clues to help on GC, will be
posting what I find as I go. This one refers to a bug in MS JScript
3.0,4.0,5.0 as related to an OLE object. It applies though.
Laters,
Ray
BUG: Excel Does Not Shut Down After Calling the Quit Method When Automating
from JScript
----------------------------------------------------------------------------
----
The information in this article applies to:
Microsoft Excel versions 2000, 2000 Service Release 1 (SR-1)
Microsoft Excel 97 for Windows
Microsoft JScript, versions 3.0, 4.0, 5.0
----------------------------------------------------------------------------
----
SYMPTOMS
When automating Microsoft Excel from Microsoft JScript, Excel stays in
memory after calling the Quit method until you close Internet Explorer or
navigate to another page.
CAUSE
JScript is holding on to a reference to Excel. Because there is a reference
on Excel when you issue the Quit command, Excel does not shut down. JScript
is a garbage collecting language, which means the engine cleans up after
itself at a certain point, and not when you set the variables to NULL. When
you shut down Internet Explorer or move to another page, the engine is
destroyed. This behavior forces garbage collection and frees the reference
to Excel.
RESOLUTION
To work around this problem, you can call the CollectGarbage method. This
forces JScript's garbage collection to occur immediately, which releases the
reference to Excel. The following code snippet illustrates how to use the
CollectGarbage method:
<HTML>
<BODY>
<INPUT type="button" value="Automate Excel" name=AutomateExcel
onclick="StartExcel()">
<SCRIPT LANGUAGE=Javascript>
var idTmr = "";
function StartExcel() {
var oExcel;
oExcel = new ActiveXObject("Excel.Application");
oExcel.Quit();
oExcel = null;
idTmr = window.setInterval("Cleanup();",1);
}
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}
</SCRIPT>
</BODY>
</HTML>
Notice that the CollectGarbage method is not called directly after Excel's
Quit method. You need to give JScript a small amount of time before calling
CollectGarbage. A timer is used in this example to show how to wait briefly
before forcing garbage collection.
Another workaround to this problem is to use VBScript for Automation of
Microsoft Excel. Unlike JScript, VBScript is not a garbage collecting
language and, therefore, references are released when you set the variables
to Nothing. Using VBScript, Excel shuts down immediately after calling the
Quit method and releasing the variables. Please see the "References" section
of this article for more information.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at
the beginning of this article.
_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev