* @throws JellyException
*/
public long runScriptManyTimes(String scriptName, int count)
throws IOException, SAXException, JellyException {
Runtime rt = Runtime.getRuntime();
JellyContext jc = new JellyContext();
jc.setClassLoader(getClass().getClassLoader());
XMLOutput output = XMLOutput.createDummyXMLOutput();
URL url = this.getClass().getResource(scriptName);
String exturl = url.toExternalForm();
int lastSlash = exturl.lastIndexOf("/");
String extBase = exturl.substring(0,lastSlash+1);
URL baseurl = new URL(extBase);
jc.setCurrentURL(baseurl);
InputStream is = url.openStream();
byte[] bytes = new byte[is.available()];
is.read(bytes);
InputStream scriptIStream = new ByteArrayInputStream(bytes);
InputSource scriptISource = new InputSource(scriptIStream);
is.close();
is = null;
bytes = null;
rt.runFinalization();
rt.gc();
long start = rt.totalMemory() - rt.freeMemory();
log.info("Starting memory test with used memory of " + start);
XMLParser parser;
Script script;
int outputEveryXIterations = outputEveryXIterations();
for (int i = 0; i < count; i++) {
scriptIStream.reset();
parser = new XMLParser();
script = parser.parse(scriptISource);
script.run(jc, output);
// PL: I don't see why but removing the clear here
// does make the test fail!
// As if the WeakHashMap wasn't weak enough...
//Hans: The structure of the relationship
// between TagScript and Tag prevents WeakHashMap
// from working in this case, which is why I removed it.
jc.clear();
if (outputEveryXIterations != 0 && i % outputEveryXIterations == 0) {
parser = null;
script = null;