in reply to Re^4: 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

Not only by adding the references, but also by including them into a list instead of using them directly. We tested it hundred times, really.
  • Comment on Re^5: what is difference between calling the function in Perl/Tk in the following ways

Replies are listed 'Best First'.
Re^6: what is difference between calling the function in Perl/Tk in the following ways
by ikegami (Patriarch) on Apr 16, 2010 at 22:17 UTC
    That would be awesome, except you seem to have forgotten to post the test.
      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.

        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