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

Re: [perl #109270] leak on accessing anon sub inside another one

Thread Previous | Thread Next
From:
David Golden
Date:
January 29, 2012 18:37
Subject:
Re: [perl #109270] leak on accessing anon sub inside another one
Message ID:
CAOeq1c8t+zt1fMQ5Dx3Ht=9PcPGSJzpp1=kYnMxC23_imLq9ig@mail.gmail.com
Without knowing your exact use-case, I'll point out that another
alternative on Perl 5.10+ could be to use state variables instead of
my variables:

  use 5.010;

  sub leak {

     state $foo = sub {  &$bar   };
     state $bar = sub {  "$foo"  };

     return;
  }

This only creates a single instance of $foo and $bar and thus doesn't
leak --  which may not be what you're looking for if you really want
to generate (and return) circular closures that change behavior with
every invocation.

-- David

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