Home Forums General XMetaL Discussion Garbage Collection Reply To: Garbage Collection

Derek Read

Reply to: Garbage Collection

The article says (to my reading) that this is an issue when Excel is embedded as a COM object inside a web page in IE. I have not tested Excel automation to the extreme but I have done some and don't recall this being an issue when interacting with Excel using scripts run from XMetaL.

Using the exact same script provided by Microsoft in this article I cannot seem to reproduce the issue when run from XMetaL Author:

[code]//XMetaL Script Language JScript:
  function StartExcel() {
    var oExcel;

    oExcel = new ActiveXObject(“Excel.Application”);
    oExcel.Quit();
    oExcel = null;
  }

StartExcel();[/code]

To test this:

1) Create an MCR containing that code and deploy it.
2) Run XMetaL Author.
3) Open Windows Task Manager to confirm that Excel is not currently listed.
4) Run the script. Excel should show up and then go away. In my testing that takes about 3 seconds. So, either setting the object to null is triggering JScript's garbage collection, or garbage collection is just deciding to run at an appropriate time.

However, if you see different results and are actually concerned that the reference to Excel will be cleaned up, the simplest solution would be to use VBScript instead. That is what the KB article recommends as an alternative. Does the same issue occur when you try VBScript? That's what I would try first.

Probably worth it to check to see if Microsoft has fixed this Excel bug in a newer release of Excel or a patch as this article seems to be quite old (2007).

In my case my Excel version is 12.0, which I can obtain with the following, almost identical, script:

[code]//XMetaL Script Language JScript:
  function StartExcel() {
    var oExcel;

    oExcel = new ActiveXObject(“Excel.Application”);
    Application.Alert(oExcel.version);
    oExcel.Quit();
    oExcel = null;
  }

StartExcel();[/code]

I see that Microsoft has added the following note to the KB article as well:

The undocumented CollectGarbage method is not part of the ECMA-262 specification, and may not be available in future versions of the scripting engine. When you force the garbage collector to run by calling CollectGarbage, this may also negatively impact performance.

…and that this article specifically lists JScript 3.0, 4.0 and 5.0. You may wish to check your version of JScript to see if that makes a difference.

[code]//XMetaL Script Language JScript:
function getJScriptVersion()
{
    var v = “”;
    v += ScriptEngineMajorVersion() + “.”;
    v += ScriptEngineMinorVersion() + “.”;
    v += ScriptEngineBuildVersion();
    return(v);
}
var jscriptversion = getJScriptVersion();
Application.Alert(jscriptversion);[/code]

In my case the version is 5.7.22145

Reply

Products
Downloads
Support