in reply to memory leak when using tail recursion?
I ran into a memory leak in a system I'm working on
I see no leekage. Memory usage is more or less constant.
#!/usr/bin/perl use strict; use warnings; sub bar { if ( foo() ) { goto &bar; } return; } my $i; sub foo { return $i++ < 500_000; } $i=0; bar(); print("Press Enter to continue"); <STDIN>; # 32,824K $i=0; bar(); print("Press Enter to continue"); <STDIN>; # 32,872K $i=0; bar(); print("Press Enter to continue"); <STDIN>; # 32,860K $i=0; bar(); print("Press Enter to continue"); <STDIN>; # 32,856K
The stack and all lexical variables should be deallocated when goto is called, right?
Should? Dunno. Does? No. ( That's why the memory usage increases for each recursive call to bar. )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: memory leak when using tail recursion?
by Limbic~Region (Chancellor) on Feb 14, 2007 at 00:07 UTC | |
by ikegami (Patriarch) on Feb 14, 2007 at 00:10 UTC | |
by Limbic~Region (Chancellor) on Feb 14, 2007 at 00:14 UTC | |
by ikegami (Patriarch) on Feb 14, 2007 at 00:20 UTC | |
by juddhuck (Acolyte) on Feb 14, 2007 at 00:29 UTC | |
| |
|
Re^2: memory leak when using tail recursion?
by juddhuck (Acolyte) on Feb 15, 2007 at 19:42 UTC |