Re: destroy xml object

Michael Ludwig <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <20100710195926.GK3036@wladimir>
Thomas Krichel schrieb am 10.07.2010 um 17:06 (+0200):
> > Thomas Krichel schrieb am 07.07.2010 um 06:40 (+0200):
> > >    A script of mine repeatedly calls 
> > >  
> > >  my $in_xml = eval {
> > >    XML::LibXML->load_xml(location=>$in_file);
> > >  };
> > >  
> > >    Memory usage goes through the roof. Eventually, the
> > >    script is killed by the kernel. In my despair I try
> > >    
> > >  $in_xml->DESTOY();
> > >  
> > >    That bombs out completely. What is a boy to do here?

Doesn't look like you're supposed to call ->DESTROY explicitly. Gives me
an error message and a SEGV:

  PmmREFCNT_dec: REFCNT decremented below 0 for 1487778!

If you want to make sure the memory is freed, make sure the variable
goes out of scope, or simply undef it.

          \,,,/
          (o o)
------oOOo-(_)-oOOo------
use warnings;
use strict;
use XML::LibXML;

my $xml_file = shift or die; # pick any well-formed XML file
my $max_parse_count = 500;   # maximum parse count
my $parse_count     =   0;

while ( $parse_count++ < $max_parse_count ) {
  print STDERR '.'; print STDERR "\n" unless $parse_count % 50;
  my $in_xml = eval { XML::LibXML->load_xml(location=>$xml_file) };
  warn $@ if $@;
  # $in_xml->DESTROY; # avoid this, may result in SEGV
  # undef $in_xml;    # okay, but unnecessary here
  <> unless $parse_count % 50; # check process size
}

-- 
Michael Ludwig
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
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.