how to release resource used by Saxon(s9api)?
Added by Anonymous over 16 years ago
Legacy ID: #5139342 Legacy Poster: y10k (y10k)
try { XQueryExecutable executable = compiler.compile(query); XQueryEvaluator evaluator = executable.load(); Serializer serializer = new Serializer(); serializer.setOutputStream(out); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); evaluator.run(serializer); } catch (SaxonApiException e) { ... } I have the above code running a XQuery file, and the XQuery file loads a big XML (>100MB). The execution of the XQuery pushes JVM memory usage to around 1.2G. After the execution is done, the 1.2G memory is not released. I tried calling garbage collector explicitly but the situation remained the same. One thing I noted is that when I tried to open the output file (the filestream to which the serializer wrote) on Windows, Windows prompted the file could not be opened. Once I shut the UI part of my program, I could open the file. Is there any special methods that I should call to get rid of this problem?
Replies (1)
RE: how to release resource used by Saxon(s9a - Added by Anonymous over 16 years ago
Legacy ID: #5139679 Legacy Poster: Michael Kay (mhkay)
You don't actually say how you are loading the source document. Using the doc() function within the query source? In that case you could try using saxon:discard-document() to ensure it is released as early as possible. But this shouldn't be necessary if your application is structured correctly - the document should be released to the garbage collector as soon as the XQueryEvaluator is released, and there's no reason to be hanging on to that. If you need to do more analysis, the HAT tool from Sun is excellent at helping you work out which objects are on the heap and why. The problem with the output file is unrelated. You created the OutputStream out, so it's your job to close it after use - that's a consistent design principle within Saxon. Until you close it, the file will be inaccessible by other Windows applications.
Please register to reply