LibXML and $node->nodePath
by Bernd Krause other posts by this author
Jun 16 2006 2:17AM messages near this date
view in the new Beta List Site
Re: Antwort: Re: LibXML and $node->nodePath
|
Re: LibXML and $node->nodePath
& XSLT 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.
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
Thread:
Bernd Krause
Petr Pajas
|