var util = require("josm/util");
if (typeof cnt === 'undefined')
cnt = 0;
else
cnt ++;
util.print("CNT: " + cnt);
This will print 0, then 1, then 2, etc. Although this is usually harmless, I think it is effectively a memory leak when there are global variables pointing to huge objects or datasets.
It can also cause cross-script interference if two scripts are using the same global variable names.
If this is technically impossible to resolve due to some limitation in Mozilla Rhino or the underlying JOSM code, then the user should at least be warned in the documentation, and advised to always wrap the code in a (function() {user code here}) (); if dealing with huge globals.
This will print 0, then 1, then 2, etc. Although this is usually harmless, I think it is effectively a memory leak when there are global variables pointing to huge objects or datasets.
It can also cause cross-script interference if two scripts are using the same global variable names.
If this is technically impossible to resolve due to some limitation in Mozilla Rhino or the underlying JOSM code, then the user should at least be warned in the documentation, and advised to always wrap the code in a
(function() {user code here}) ();
if dealing with huge globals.