in reply to Re^5: memory leak when using tail recursion?
in thread memory leak when using tail recursion?

That's interesting. The following code doesn't leak though:
#!/usr/bin/perl use strict; use warnings; bar(); sub bar { my $result = foo(); if ( $result ) { goto &bar; } return; } my $i = 0; sub foo { return $i++ < 1_000_000_000; }
Wouldn't this leak if the if-statement was creating a stack frame as you said?

Replies are listed 'Best First'.
Re^7: memory leak when using tail recursion?
by ikegami (Patriarch) on Feb 14, 2007 at 00:38 UTC
    Intersting! I'm even willing to dive into the guts to see if I can find the answer, but I can't tonight.
Re^7: memory leak when using tail recursion?
by ikegami (Patriarch) on Mar 15, 2007 at 01:05 UTC

    I confused "scope" with "stack frame". While if creates a lexical scope, no stack frame is created.

    Because if creates a lexical scope, the following dies:

    >perl -e "use strict; if (my $x = foo()) { } print $x; Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

    If if created a stack frame, the following would print abcde instead of abced:

    sub P1::DESTROY { print 'd'; } sub P2::DESTROY { print 'c'; } { print('a'); if (my $x = bless({}, 'P1')) { my $y = bless({}, 'P2'); print('b'); } print('e'); } print("\n");

    Anyway, I didn't find an answer to your question.