Hi,

I notice the example code repeatedly calls document('../conf/site.xml').

Question for XALAN developers: Does the "document" function recognise
when it a document has previously been loaded, or does it reparse the
specified document each time?

I had a look at the source (org.apache.xalan.templates.FuncDocument) but
it wasn't immediately obvious whether Xalan keeps a cache of previously
loaded documents or not.

If it doesn't (and I suspect this is the case), then you are loading,
parsing, and generating a complete in-memory representation of
"site.xml" 4 times in the fragment below. This might be the cause of the
unexpectedly large memory usage, particularly if site.xml is a large
document.

I suggest you add the following at global level:

<xsl:variable name="sitedoc" select="document('../conf/site.xml')"/>

then use code like 

<a href="{$sitedoc/.......}">

Hope this helps,

Simon

On Mon, 2002-12-16 at 11:09, Christian Wolfgang Hujer wrote:
> Hello dear Xalan users,
> 
> 
> I use Ant (1.5.1), Xalan (2.4.1) and Xerces (2.2.1) to do some XHTML2XHTML 
> transformations. After adding some document()-functions, I quickly ran out of 
> memory, receiving a java.lang.OutOfMemoryError.
> 
> None of the documents is huge or even big in size, all documents are 
> well-formed, all XHTML documents are valid.
> 
> I temporarily work-around the problem by using ANT_OPTS="$ANT_OPTS -Xmx256M" 
> in my ~/.antrc.
> 
> To get an impression of what my stylesheets look like, I've added a code 
> snippet:
> 
>     <xsl:template name="createNavigation">
>         <xsl:for-each 
> select="document('../conf/site.xml')/site/pagesequence/pageref">
>             <xsl:variable name="id" select="@id"/><!-- introduced because 
> using current() threw a NullPointerException in img's alt attribute -->
>             <a 
> href="/{document('../conf/site.xml')/site/pagedefs/[EMAIL PROTECTED]/[EMAIL 
> PROTECTED]'de']/@href}">
>                 <img
>                     
> src="/gfx/{document('../conf/site.xml')/site/pagedefs/[EMAIL 
> PROTECTED]/[EMAIL PROTECTED]'de']/@href}_button.png"
>                     alt="{document(concat('../htdocs/', 
> document('../conf/site.xml')/site/pagedefs/[EMAIL PROTECTED]/[EMAIL 
> PROTECTED]'de']/@href, 
> '.php'))/html:html/html:head/html:[EMAIL PROTECTED]'ITCQIS' and 
> @name='buttontext']/@content}"
>                     class="decorblock"
>                 />
>             </a>
>         </xsl:for-each>
>     </xsl:template>
> 
> I use an Ant script with an XML Catalog. It invokes XMLValidate, XSLT and 
> XMLValidate again. It also invokes Rasterize, but the memory footprint of 
> Rasterize is quite low, especially compared with XSLT.
> 
> When the build.xml had to transform the 11th document, it ran out of memory. 
> Memory consumption exceeded 90 MBytes.
> When following memory consumption using top I detected that the memory usage 
> increases by approximately 15 MBytes per transformation and goes far beyond 
> 120 MBytes - just for validating, transforming and again validating 11 files.
> 
> It seems that many objects do not get garbage collected because unneccessary 
> references to them remain.
> 
> I profiled the application. When profiled, the application once needed 212 
> MBytes of RAM (whereas part of the memory is, of course, consumed by the 
> profiler itself).
> 
> Has anyone else experienced such memory problems?
> 
> I can send a memory profile (gzipped, of course, still >1MB) or even give a 
> login to my machine to view it locally, including all scripts.
> 
> 
> Bye
-- 
Simon Kitching <[EMAIL PROTECTED]>

Reply via email to