HTML::TreeBuilder 中的内存泄漏

发布于 2024-09-12 16:32:55 字数 516 浏览 4 评论 0原文

我有一些 Perl 代码:

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 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
}

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-09-19 16:32:55

我无法使用以下脚本复制此内容:

#!/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 之间。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文