Re: LibXML and $node->nodePath
by Petr Pajas other posts by this author
Jun 16 2006 4:35AM messages near this date
view in the new Beta List Site
LibXML and $node->nodePath
|
DTD to web form
& XSLT On Friday 16 June 2006 10:54, Bernd Krause wrote:
> Hi,
>
> I am using the XML::LibXML function $node->nodePath. This is not a
> documented function but has been discussed on this list.
> I am observing a memory leak as soon as I use $node->nodePath.
>
> Consider the following sample code:
> =========================================
> use strict;
> use XML::LibXML;
>
> my $i = 0;
> my $loop_end = 20000;
> my $xml_string = '<?xml
> version="1.0"?><root><aaa><bbb/><ccc/></aaa><ddd><bbb/><eee/></ddd></root>'
> ;
>
> my $parser = XML::LibXML->new();
> my $tree = $parser->parse_string($xml_string) || die;
> for ($i = 0; $i <= $loop_end; $i++) {
>
> my $root = $tree->getDocumentElement;
> my $dtd = $root->nodeName;
> my $xpath_string = "//*";
>
> foreach my $node ($tree->findnodes("$xpath_string")){
> my $xPath = $node->nodePath; # <- problem
> }
> print $i, "\t", $dtd, "\n";
> }
> =========================================
>
> If the above code is executed, computer memory consumption increases
> linearly with $loop_end.
> However, removing the $node->nodePath instruction immediately resolves the
> problem: memory consumption remains constant independant of $loop_end.
>
> This is not a real problem for single file parsing. The problem occurs
> because I have to parse a large number of XML files (much larger and more
> complicated than in the example above). LibXML does a great job on that,
> it is only the $node->nodePath which eats up all memory and makes my
> computer stop working.
A totally stupid bug indeed. The definition of nodePath in LibXML.xs misses a
xmlFree call. It should look like:
nodePath( self )
xmlNodePtr self
PREINIT:
xmlChar * path = NULL;
CODE:
path = xmlGetNodePath( self );
if ( path == NULL ) {
croak( "cannot calculate path for the given node" );
}
RETVAL = nodeC2Sv( path, self );
xmlFree( path ); /* this line was missing !!! */
OUTPUT:
RETVAL
Since axkit was reinstalled I don't have write access to the CVS, so I can't
fix it permanently ATM. I'll see what I can do about it.
-- Petr
> My Perl/LibXML environment is:
>
> Windows 2000
> Active State PERL v5.8.3
>
> XML::LibXML::LIBXML_DOTTED_VERSION -> 2.6.11
> XML::LibXML::LIBXML_VERSION -> 20611
> XML::LibXML::VERSION -> 1.58
>
> Is there any way to prevent $node->nodePath from consuming all memory?
> Thanks in advance for any help,
> Bernd
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Bernd Krause
Petr Pajas
|