General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Garbage Collection
-
sapraaman June 21, 2010 at 5:35 am
Garbage Collection
June 21, 2010 at 5:35 amParticipants 2Replies 3Last Activity 12 years, 9 months agoHi,
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,
AmanDerek Read June 21, 2010 at 7:06 pm
Reply to: Garbage Collection
June 21, 2010 at 7:06 pmThe 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
sapraaman June 22, 2010 at 9:25 am
Reply to: Garbage Collection
June 22, 2010 at 9:25 amThanks Derek. Let me work on it.
Derek Read June 22, 2010 at 7:22 pm
Reply to: Garbage Collection
June 22, 2010 at 7:22 pmI'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.
-
AuthorPosts
- You must be logged in to reply to this topic.