develooper Front page | perl.perl5.porters | Postings from January 2003

Re: Freeing code

Thread Previous | Thread Next
From:
notthatbbennett
Date:
January 27, 2003 05:24
Subject:
Re: Freeing code
Message ID:
2003-01-27-1714-20287@dbl-b.com
on 2003-01-24 13:01:54-06, mjtg@cam.ac.uk wrote:
>notthatbbennett@yahoo.com (Bill Bennett) wrote
>> When the last pointer to an anonymous subroutine is derefed, is
>> the space into which the code is compiled free'd?
>
>It should be.
>
>> I think not, based on observations.  Is this correct?
>
>Some bugs in this area have been fixed recently.    If your 
>observations are based on a Perl version earlier that 5.8.0, 
>please try again with this version.    If you still see a leak 
>you've discovered a new bug  -
>please tell perlbug about it.
>
>
>Mike Guy

I don't know whether this is really a bug, or if I'm inadvertently
creating some sort of circular reference, but here is the 
observation.  The code in example 1 doesn't leak memory, but
the code in example 2 does (at least it increases in size, slowly
but steadily as it runs).  I am running perl 5.8.0 under 
RedHat 8.0.  If anyone can explain this behavior as other than a
bug, I'd like to know the explanation.  Otherwise, I'll report it
to perlbug.

*****Begin example 1*******
#!/usr/bin/perl
sub def{
  my($fie) = @_;
  my $sub = sub {
    my($foo) = @_;
    return $foo + $fie;
  };
  return $sub;
}

my $i;
for $i (0 .. 100000000){
  my $func = def($i);
  if($@){ die $@ }
  my $sum = &$func($i);
  unless($sum == 2 * $i){ die "error" };
}
*****End example 1*********
*****Begin example 2*******
#!/usr/bin/perl
sub def{
  my($foo, $fie) = @_;
  return eval($foo);
}
my $Definition = <<EOF;
sub {
  my(\$foo) = \@_;
  return \$foo + \$fie;
}
EOF
print $Definition;
my $i;
for $i (0 .. 100000000){
  my $func = def($Definition, $i);
  if($@){ die $@ }
  my $sum = &$func($i);
  unless($sum == 2 * $i){ die "error" };
}
*****End example 2*********


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About