Re: Memory Leak?

Chris Cheung <[email protected]>
Newsgroups gmane.text.xml.xerces-p.devel
Message-ID <Pine.LNX.4.44.0311141659060.25310-300000@mars.cluster.clc.cuhk.edu.hk>
Dear Jason,

On 14 Nov 2003, Jason E. Stewart wrote:

> Apparently, one user indicated that if he turned validation off the
> memory leak went away. He was using a SAX2 parser, however. So please
> try this for your application and let us know if it helps.


  Thanks a lot for your help. I tried turning validation off but the 
memory leak still occurs. Attached please find two Perl scripts producing 
the memory leak - one for XML parsing and one for pretty-printing 
independently. The example XML I used is about 60k bytes. The variables 
are local in the for-loop so I suppose it will be destroyed at the end of 
the for-loop in each iteration.

The memory leak by mleak2.pl grow to >400M (500 iterations).

If I comment out the statement with $parser->adoptDocument, the memory 
leak grow only to 35M.
Do I need to call some API to clean up after calling 
XML::Xerces::AbstractDOMParser::adoptDocument() ?

The memory leak by mleak3.pl grow to about 150M (2500 iterations)

Hope this help. Thanks again.

-- 
Best Regards,

Chris Cheung
Center for Large-Scale Computation

Have a nice day!

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
mleak2.pl (text/plain, 743 B)
#!/usr/bin/perl -w

use XML::Xerces;

my $xml;

{
	open(F, "< example.xml") || die "Cannot open file.";
	# setting the delimiter to undef to read the whole XML as a string.
	$/=undef;
	$xml = <F>;
}

for (my $i = 0; $i < 500; $i++)
{
    my $parser = XML::Xerces::XercesDOMParser->new();
    $parser->setDoNamespaces(1);

	$parser->setValidationScheme(
	                    $XML::Xerces::AbstractDOMParser::Val_Never);

	$parser->parse(XML::Xerces::MemBufInputSource->new($xml));

	# I used adoptDocument since I need to use the DOMDocument after
	# the parser die.
	# Do I need to call some clean-up API afterward?
	my $doc = $parser->adoptDocument();

	print "$i\n";
}


print "Test Ended\n";
sleep 100000;
mleak3.pl (text/plain, 770 B)
#!/usr/bin/perl -w

use XML::Xerces;

my $parser = XML::Xerces::XercesDOMParser->new();
$parser->setDoNamespaces(1);

$parser->setValidationScheme(
					$XML::Xerces::AbstractDOMParser::Val_Never);

$parser->parse("example.xml");
my $doc = $parser->adoptDocument();

for (my $i = 0; $i < 2500; $i++)
{
	my $domImpl = 
		XML::Xerces::DOMImplementationRegistry::getDOMImplementation('LS');

	my $writer = $domImpl->createDOMWriter();

    if ($writer->canSetFeature('format-pretty-print',1))
	{
		$writer->setFeature('format-pretty-print',1);
	}

	my $target = XML::Xerces::MemBufFormatTarget->new();
	$writer->writeNode($target, $doc);

	my $prettyXML = $target->getRawBuffer();

	print "$i\n";
}


print "Test Ended\n";
sleep 100000;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.