http://qs321.pair.com?node_id=1159199


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

Thanks, much clearer now what is happening.

Still my argument stands, a bazillion code snippets to free the same single memory location is (at least from the perspective of the script writer) a memory leak. The questions is only if it is advisable to fix it since the fix would probably incur a heavy runtime cost.

It will only affect long running polling code in a few specific cases (for example microcontroller scripts to measure environmental stuff could fall into the trap). It is avoidable but the program writer would need to know information about an implementation detail of "my" that is not in the man pages at the moment.

Replies are listed 'Best First'.
Re^7: "goto" memory leak
by Anonymous Monk on Mar 31, 2016 at 14:36 UTC

    If it's any easier, think of my as malloc(). Inside a while loop, the my variable goes out of scope each iteration, so the storage may be reclaimed. To get the same effect with a goto loop, you'll need explicit block scoping:

    again: { my $h; } goto again;