Re: XML::Twig - Memory usage problem
mirod <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
mirod wrote: > howard chen wrote: > >> On Wed, Nov 5, 2008 at 1:07 AM, mirod <[email protected]> wrote: >>> If your XML includes id attributes, you can either use the id => undef option >>> when you create the twig, or use the updated version on my site. >> Are you sure problem only exist with "id attributes" ? I don't have >> the "id" attribute in my example XML provided. (In fact, no attributes >> used at my XML), >> However, I do have a node called "company_id". Don't know if it is related. > > It is not related. It's really only with an id attribute. > > When there are id attributes in the XML (given by the id option or just 'id' by > default), then XL::Twig keeps a hash { id => element } . This way you can get > efficiently the element from the id, using elt_id (or getElementById) on the > twig. The value, the reference to the element, is weakened, so this doesn't > prevent the element to be destroyed by a purge, but the entry in the hash > remained, which can add up to quite a bit of wasted memory after a while. > > If you don't have id's, then I still haven't been able to reproduce the leak. > Back to the drawing board I guess. I am afraid I can't reproduce the leak. The code I am testing is the one you sent in your first email, but I see no leak with it. Could you maybe give me some more details on what you do in the company sub? And the result of perl -v? The system I test on gives 'This is perl, v5.8.8 built for x86_64-linux-thread-multi'. Thanks #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $doc= shift @ARGV; print "testing more complex handler on $doc "; END { print "- size: ", memory_size(), "\n"; } # display memory size sub memory_size { open( my $status, '<', "/proc/$$/status") or die "cannot find status info in /proc/$$/status: $!"; my( $size)= map { m{^VmSize:\s+(\d+\s+\w+)} } <$status>; $size=~ s{(\d\d\d )}{ $1}; return $size; } my $tx= TextXML->new; $tx->parse( $doc); package TextXML; sub new { return bless {}; } sub parse { my( $self, $doc)= @_; my $t = XML::Twig->new( twig_handlers => { company => sub { $self->company( $_[0], $_[1] ); $_[0]->purge; }, } ); $t->parsefile( $doc ); $t->purge; } sub company { my ( $self, $t, $elt ) = @_; my @data= map { $_->tag => $_->text } $elt->children; $elt->first_child( 'company_id')->subs_text( qr{^c(\d+)}, '$elt( c => $1)'); } _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs