Subject: | Memory leak |
When using the attached PerlIO::via::Bzip2-using script with a
bzip2-compressed file of size 21M (uncompressed 222M) then I observe a
memory leak, both with perl5.8.8 and perl5.10.0:
$ perl5.8.8 /tmp/bz2.pl misc/download/osm/brandenburg.osm.bz2
13942784, 2797568 at /tmp/bz2.pl line 72.
330870784, 318656512 at /tmp/bz2.pl line 79.
$ perl5.10.0 /tmp/bz2.pl misc/download/osm/brandenburg.osm.bz2
12578816, 2465792 at /tmp/bz2.pl line 72.
262160384, 250978304 at /tmp/bz2.pl line 79.
This is on a FreeBSD 7.0 system. An equivalent script using PerlIO::gzip
shows no memory leak.
Regards,
Slaven
Subject: | bz2.pl |
#!/usr/bin/perl -w
use strict;
use PerlIO::via::Bzip2;
######################################################################
sub currmem {
my $pid = shift || $$;
no warnings 'portable'; # because of possible large hex values on 64bit systems
if ($^O eq 'freebsd' && open(MAP, "dd if=/proc/$pid/map bs=64k 2>/dev/null |")) { # FreeBSD
my $mem = 0;
my $realmem = 0;
while(<MAP>) {
my(@l) = split /\s+/;
my $delta = (hex($l[1])-hex($l[0]));
$mem += $delta;
if ($l[11] ne 'vnode') {
$realmem += $delta;
}
}
close MAP;
($mem, $realmem);
} elsif ($^O eq 'linux' && open(MAP, "/proc/$pid/maps")) { # Linux
my $mem = 0;
my $realmem = 0;
while(<MAP>) {
my(@l) = split /\s+/;
my($start,$end) = split /-/, $l[0];
my $delta = (hex($end)-hex($start));
$mem += $delta;
if (!defined $l[5] || $l[5] eq '') {
$realmem += $delta;
}
}
close MAP;
($mem, $realmem);
} else {
undef;
}
}
######################################################################
warn join(", ", currmem);
open my $fh, "<:via(Bzip2)", shift
or die "Cannot open: $!";
while(<$fh>) {
}
warn join(", ", currmem);
__END__