in reply to Re: "goto" memory leak
in thread "goto" memory leak

That depends on how you define "memory leak".

At least under Wikipedias definition ("In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations1 in such a way that memory which is no longer needed is not released.") this still is a leak. Because the main scope is never exited (while the program is running) there is at least one scope that never releases its memory.

And then there are closures. See the following code that also exhibits the memory leak:

#!/usr/bin/perl my $i; top: while (1) { again: my $x; $i = 0; goto again if $i++ < 100_000; } goto top;

Necessarily the hook variable has to be in the main scope (I assume), but the interesting thing is that the code seems to be minimal for the closure case, i.e. $i creates the closure, but $x is needed to create the leak.

UPDATE:Anon Monk found a silly mistake in my code, the inner goto is an endless loop. The conclusion is wrong, I tested closures with teh following code and memory stayed low.

sub closure { my $s; return sub { $s=5; my $i; } } my $f = closure(); while (1) { $f->(); }