in reply to Re^5: what is difference between calling the function in Perl/Tk in the following ways
in thread what is difference between calling the function in Perl/Tk in the following ways

That would be awesome, except you seem to have forgotten to post the test.
  • Comment on Re^6: what is difference between calling the function in Perl/Tk in the following ways

Replies are listed 'Best First'.
Re^7: what is difference between calling the function in Perl/Tk in the following ways
by choroba (Cardinal) on Apr 17, 2010 at 20:22 UTC
    We did the testing with perl 5.6 several years ago. Another danger of the non-list approach is that the function sees the lexical context of its definition and can accidentaly use something from there, which might also leak.

    As of now, perl 5.10.0, Tk 804.028, even this code leaks:

    perl -e 'use Tk;use Tk::Button;my $top = new MainWindow;for (1..100) { for (1..1000) { $top->Button(-text=>"foo")->destroy; } sleep 1; } '

      There's no function in there, so it supports what I guessed: It's got nothing to do with closures.

      Another danger of the non-list approach is that the function sees the lexical context of its definition and can accidentally use something from there

      No, they don't accidentally capture anything. Closures only capture the variables they need.

      The following shows that $x wasn't captured even though it was visible to the capture.

      use strict; use warnings; printf "x=%s\n", do { my $x = 2; sub { $x } }->() // 'undef'; printf "x=%s\n", do { my $x = 2; sub { eval '$x' } }->() // 'undef';
      x=2 Variable "$x" is not available at (eval 1) line 2. x=undef

      The warning is new, but the behaviour is ancient.

        I perhaps do not use English conjunctions (or other words) in the right way, for which I apologize. But by accidental leaking I meant an error made by the programmer (like missing "my" inside of the annonymous sub), not by perl. And the example of the behaviour of Button was given to show why I am no longer able to reproduce the tests we did.
      Hi,

      maybe you could check this using the latest devel release Tk-804.028_502. Your code should not leak - and I do not see it leaking using 804.028_501.

      Cheers, Christoph