memory leak in HTML::TreeBuilder
I have some Perl code:
use HTML::Parse;
use HTML::FormatText;
# ...
my $txtFormatter = HTML::FormatText->new();
while ( ... ) { # some condition
my $txt =开发者_StackOverflow # get from a file
my $html_tree = HTML::TreeBuilder->new_from_content($txt);
$txt = $txtFormatter->format($html_tree);
$html_tree->delete();
# write $txt to a file
}
I noticed the perl.exe
process steadily increases in size (up to 600 MB after 2 million or so loop iterations). If I take out the HTML::TreeBuilder
stuff, it does not increase at all. Is there anything I can do to plug this leak?
I cannot replicate this with the following script:
#!/usr/bin/perl
use strict; use warnings;
use File::Slurp;
use HTML::FormatText;
use HTML::TreeBuilder;
my $formatter = HTML::FormatText->new;
my $html = read_file 'test.html';
while ( 1 ) {
my $tree = HTML::TreeBuilder->new_from_content( $html );
$formatter->format( $tree );
$tree->delete;
}
I let this script run for minutes and the memory usage (in Task Manager) remained between 7,200K and 7,300K.
E:\Home> perl -v This is perl, v5.10.1 built for MSWin32-x86-multi-thread (with 2 registered patches, see perl -V for more detail) Copyright 1987-2009, Larry Wall Binary build 1006 [291086] provided by ActiveState http://www.ActiveState.com Built Aug 24 2009 13:48:26
E:\Home> perl -MHTML::TreeBuilder -e "print $HTML::TreeBuilder::VERSION" 3.23
E:\Home> perl -MHTML::FormatText -e "print $HTML::FormatText::VERSION" 2.04
精彩评论