General XMetaL Discussion

  • sapraaman

    Garbage Collection

    Participants 2
    Replies 3
    Last Activity 12 years ago

    Hi,

    I am trying to use “Excel.Application” COM object in jscript macro to read from excel file. Now, its a known microsoft issue that the COM object is not released till GC runs. So they have provided a workaround here.

    http://support.microsoft.com/kb/266088

    Now my question is how to call “setInterval” and “CollectGarbage” methods in the macro?

    We are using XMetal 5.5

    Thanks,
    Aman

    Reply

    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

    sapraaman

    Reply to: Garbage Collection

    Thanks Derek. Let me work on it.

    Reply

    Derek Read

    Reply to: Garbage Collection

    I've tried this on a few separate machines here and my personal Windows 7 64-bit laptop at home,  and in all cases the results are the same. With my laptop the cleanup occurs far faster (instantaneous in fact or less than 1 second). The Excel version is also 12.0 but JScript reports 5.8.x (can't remember the full number exactly). So, maybe it is just the faster machine, Windows 7, or the slightly newer JScript engine in that case.

    Anyway, I have yet to reproduce any garbage collection problems. Let me know if you do what the exact steps are.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support