本文介绍了HTML :: TreeBuilder中的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些Perl代码:
I have some Perl code:
use HTML::Parse;
use HTML::FormatText;
# ...
my $txtFormatter = HTML::FormatText->new();
while ( ... ) { # some condition
my $txt = # 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
}
我注意到perl.exe
进程的大小稳步增加(经过200万次左右的循环迭代后达到600 MB).如果我拿出HTML::TreeBuilder
东西,它根本不会增加.我有什么办法可以解决此泄漏吗?
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;
}
我让此脚本运行了几分钟,并且(任务管理器中的)内存使用量保持在7,200K到7,300K之间.
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
这篇关于HTML :: TreeBuilder中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!