in reply to Lost anonymous subs

Will it be garbage-collected? Anonymous subs cannot be GCed as far as I understand.

Unreferenced subroutines should be destroyed and garbage collected in perl (general caveats about circular references probably apply to subs too, I guess). IIRC there have been some problems in the past with memory leaks when removing subs (bugs in the perl interpreter: creating and destroying subs is valid and supported), so I just tested the following code in 5.8.5 and the process's memory use doesn't grow at all (it seems to be safe):

#!/usr/local/bin/perl -w use strict; while (1) { my @arr = 'x' x 1000000; my $subref = sub { @arr; } }