Subject: | Memory leak on perl 5.8.8 |
I am seeing a memory leak when creating (and immediately destroying)
lots of Safe objects. This is with perl 5.8.8 and Safe 2.27. Attached is
a fairly simple script which demonstrates the issue. Creating 100 Safe
objects shows a couple of leaks of about 135000 bytes.
I think this is a general 5.8.8 problem but, for information, I am doing
this on RHEL5.5 with perl 5.8.8-32.el5_5.1. I have also seen this with
Safe 2.12 and 5.8.8-27.el5 but then it takes in the order of 10,000
objects to cause leaks. I have reports that this also occurs on SLES 10
with perl 5.8.8 and Safe 2.12. I have tried this with perl 5.10 on
Fedora 13 and cannot make it leak even with 100,000 object creations.
Stephen
Subject: | safe_leak.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Safe ();
use IO::File ();
my $num = $ARGV[0] || 1000;
my $cur_size = get_rss();
print "Start size: $cur_size\n";
for my $i (1..$num) {
my $cpt = Safe->new();
my $new_size = get_rss();
my $change = $new_size - $cur_size;
if ( $change > 0 ) {
print "Iteration $i: Memory usage changed: $change\n";
$cur_size = $new_size;
}
}
sub get_rss {
my $file = "/proc/$$/stat";
my $fh = IO::File->new( $file, 'r' ) or die "Could not open $file: $!\n";
chomp( my $data = <$fh> );
$fh->close;
my $rss = (split ' ', $data)[22];
return $rss;
}