in reply to Lost anonymous subs
No, @arr is still accessible:
my @arr = (9) x 1000_000; my $code = sub { @arr }; undef $code; print(scalar(@arr), $/); # 1000000
You might mean
my $code; { my @arr = (9) x 1000_000; $code = sub { @arr }; } # @arr kept alive by the sub undef $code; # @arr freed print(scalar(@arr), $/); # error under strict.
@arr would be freed at the undef. The memory is released to perl, but maybe not to the OS. There has been discussion on this in the past.
Nit: perl uses reference counting, not garbage collection.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Lost anonymous subs
by kappa (Chaplain) on Dec 09, 2004 at 16:02 UTC | |
by diotalevi (Canon) on Dec 09, 2004 at 17:21 UTC | |
by kappa (Chaplain) on Dec 10, 2004 at 12:07 UTC | |
by diotalevi (Canon) on Dec 10, 2004 at 15:02 UTC | |
by kappa (Chaplain) on Dec 10, 2004 at 15:27 UTC | |
| |
by ysth (Canon) on Dec 10, 2004 at 11:50 UTC | |
|
Re^2: Lost anonymous subs
by chb (Deacon) on Dec 10, 2004 at 08:55 UTC |