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

Re: Freeing code

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
January 27, 2003 05:51
Subject:
Re: Freeing code
Message ID:
20030127134748.G2451@fdgroup.com
On Mon, Jan 27, 2003 at 07:30:14AM -0600, Bill Bennett wrote:
> 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.

Hmm, I get constant memory for the 2nd example on Solaris, both for
5.8.0 and bleedperl. I don't have accesss to an RH8 box to try it on.

Are you using the stock Perl that comes with Redhat 8, or did you build
your own? In either case, could you show the output of

    perl -V

Thanks.

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

-- 
"Emacs isn't a bad OS once you get used to it.
It just lacks a decent editor."

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