juddhuck has asked for the wisdom of the Perl Monks concerning the following question:
I ran into a memory leak in a system I'm working on, and I narrowed it down to a problem when using "goto &subroutine" for tail recursion. Here is a simple script that recreates the problem:
This script quickly leaks memory, but if I just move the contents of foo() into the if conditional, it doesn't leak at all. Also, if I move the call to foo() before the conditional it doesn't leak.#!/usr/bin/perl use strict; use warnings; bar(); sub bar { if ( foo() ) { goto &bar; } return; } my $i = 0; sub foo { return $i++ < 1_000_000_000; }
The stack and all lexical variables should be deallocated when goto is called, right? I think something strange is happening with the memory used for the return value of foo() when it is called in the conditional block. Any ideas?
Thanks,
Justin
|
|---|