Mailing List Archive

Re: 5.001m s/foo/5+5/ee Memory Leak!
[.courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc,
Cameron Elliott <cam@indy.mvbms.com> writes:
:I am writing an HTTP daemon in perl, and am having a problem
:removing a memory leak.
:
:
:Hence the following program:
:#!/usr/local/bin/perl
:
:for(;;) {
:$test = 'This is a simple program';
: $test =~ s/simple/5+5/ee;
:}
:
:
:This puppy eats memory like there is no tommorow, please help me
:solve this.
:(I do need the double 'ee' functionallity, which is the problem)

While that's probably a bug, be apprised that most /ee functionality can
be achieved via careful closures and /e.

$foo = '$1 + $2';
s/(\d+)\s+(\d+)/$foo/ee;

Could have been

$foo = sub { $1 + $2 };
s/(\d+)\s+(\d+)/&$foo/;

--tom
Re: 5.001m s/foo/5+5/ee Memory Leak! [ In reply to ]
: [.courtesy cc of this posting sent to cited author via email]
:
: In comp.lang.perl.misc,
: Cameron Elliott <cam@indy.mvbms.com> writes:
: :I am writing an HTTP daemon in perl, and am having a problem
: :removing a memory leak.
: :
: :
: :Hence the following program:
: :#!/usr/local/bin/perl
: :
: :for(;;) {
: :$test = 'This is a simple program';
: : $test =~ s/simple/5+5/ee;
: :}
: :
: :
: :This puppy eats memory like there is no tommorow, please help me
: :solve this.
: :(I do need the double 'ee' functionallity, which is the problem)

It's just the standard 5.001 eval leak. It should not be leaking in
5.002beta1.

: While that's probably a bug, be apprised that most /ee functionality can
: be achieved via careful closures and /e.
:
: $foo = '$1 + $2';
: s/(\d+)\s+(\d+)/$foo/ee;
:
: Could have been
:
: $foo = sub { $1 + $2 };
: s/(\d+)\s+(\d+)/&$foo/;

Not without at least one /e (or use of the @{[&$foo]} trick).

Larry
Re: 5.001m s/foo/5+5/ee Memory Leak! [ In reply to ]
>: While that's probably a bug, be apprised that most /ee functionality can
cured
>: be achieved via careful closures and /e.
>:
>: $foo = '$1 + $2';
>: s/(\d+)\s+(\d+)/$foo/ee;
>:
>: Could have been
>:
>: $foo = sub { $1 + $2 };
>: s/(\d+)\s+(\d+)/&$foo/;

>Not without at least one /e (or use of the @{[&$foo]} trick).

Sigh. I type too fast, and read too little. :-) That's what I meant.

The single /e is ok.

--tom