DOMInputSource vs InputSource (was Re: Memory Leak?)
Brian Faull <[email protected]>
| Newsgroups | gmane.text.xml.xerces-p.devel |
|---|---|
| Organization | The MITRE Corporation |
| Message-ID | <[email protected]> |
Jason, et al, Trying to implement the solution you list -- but I need to take input from a local variable. My previous attempt used a XercesDOMParser rather than DOMBuilder... and XercesDOMParser::parse was AbstractDOMParser::parse, which took an InputSource (can be StdIn*, MemBuf*, LocalFile*, ...). DOMBuilder::parse rather takes a DOMInputSource, which seems that it may only be a file or URL natively. There is a handy class called Wrapper4InputSource which isa DOMInputSource which can allow an InputSource to be used as a DOMInputSource. However... Wrapper4InputSource doesn't appear to be available in XML::Xerces. I didn't see any tests with a DOMInputSource used, either... Have I missed something, or...? -brian "Jason E. Stewart" wrote: > > Chris Cheung <[email protected]> writes: > > > I need to use Xerces-Perl to repeatedly > > > > - parse XML to DOM tree > > - manipulate the DOM tree > > - pretty-print the DOM tree > > > > It seems that serious memory leak occurs. I do not hold any reference to > > the Perl Xerces object used in the programme and hence the Perl objects > > should be DESTROYed after use, but memory usage keeps on increasing as > > reported by the OS. > > Hi Chris, > > So I think I've solved this. First use DOMBuilder, and second ensure > that resetDocumentPool() gets called after you are finished with the > DOM tree. Here's some code stolen from my memtest.pl: > > my $impl = XML::Xerces::DOMImplementationRegistry::getDOMImplementation('LS'); > my $parser = $impl->createDOMBuilder($XML::Xerces::DOMImplementationLS::MODE_SYNCHRONOUS,''); > > sub validate_builder { > my $xml = shift ; > my $parser = shift; > > eval { > $parser->setFeature("$XML::Xerces::XMLUni::fgDOMNamespaces", $namespace) ; > $parser->setFeature("$XML::Xerces::XMLUni::fgXercesSchema", $schema) ; > $parser->setFeature("$XML::Xerces::XMLUni::fgXercesSchemaFullChecking", $schema) ; > # $parser->setFeature("http://apache.org/xml/features/validation-error-as-fatal", $validate) ; > }; > XML::Xerces::error($@) if $@; > > eval { > $parser->setFeature("$XML::Xerces::XMLUni::fgDOMValidation", $validate) ; > # $parser->setFeature("$XML::Xerces::XMLUni::fgDOMValidateIfSchema", 0) ; > }; > XML::Xerces::error($@) if $@; > > eval { > # my $is = XML::Xerces::MemBufInputSource->new($xml); > # my $is = XML::Xerces::LocalFileInputSource->new($OPTIONS{file}); > $parser->parseURI($OPTIONS{file}) ; > } ; > XML::Xerces::error($@) if $@; > $parser->resetDocumentPool(); > } > > Using this code I'm not getting any perceptable leaks with 2.3.0-4. > > Let me know if this helps, > jas. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] -- Brian Faull Senior Integrated Electronics Engineer D620 - Communications and Networking The MITRE Corporation 202 Burlington Road, MS E015 Bedford, MA 01730-1420 V:781.271.5736 F:781.271.8875 mailto:[email protected]