You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by ko...@inventivedesigners.com on 2002/05/23 08:55:07 UTC

Memory trouble with Xalan extension returning a node-set

Hi,

I'm writing a stylesheet that needs to maintain a global state of variables
during transformation. I wrote an extension to Xalan in Java to maintain
this state through simple 'get' and 'set' functions.
Now, I wanted to retrieve that state as a node-set in order to do something
like this:

<xsl:template name="apply-current-state">
  <xsl:for-each select="ext:getState()">
    ... do something with state
  </xsl:for-each>
</xsl:template>

The state is maintained as a node-set that is manipulated in my Java-class.
My extension-method is implemented along these lines:

public Node getState ()
{
  return fStateNode; // fStateNode is actually an Element;
}

Now comes the problem: if I do it as shown above, every application of
'apply-current-state' (every call of ext:getState()) results in the *same
state*;
even when it has been altered in the meantime. I figure this is because
Xalan
thinks I am returing the same node over and over again, without knowing
that
I have altered it. (is this correct?)

That's why I tried:
public Node getState ()
{
  return fStateNode.cloneNode(true);
}

... but this leads to a *huge* memory-leak. Where the first approach never
consumes more than 5MB; the latter explodes to up to 256MB before crashing
on my 800kb XML-document...