Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I wonder why for any line in group "1" (somehow most of them contain a "for"; though a couple are void contexts) Perl sits on unreleased RAM (presumably useful for further, not shown lines of a program); but for any of the "2", the 3d RAM probing reveals the memory was released i.e it's again the initial ~ 10 Mb consumed.
use strict; use warnings; use feature 'say'; use Thread::Queue; sub memory { qx( tasklist/nh /fi "PID eq $$" ) =~ /(\S+ K)$/ } # Stra +wberry my $q = Thread::Queue-> new; say memory; { my $n = 1e9; my $s = 'x' x $n; # avoid compile-time folding $q-> enqueue( $s ); $q-> end; } say memory; { my $tmp; for ( 1 ) { $tmp = $q-> dequeue } # 1 # for ( $q ) { my $tmp = $_-> dequeue } # # my $tmp; for ( $q ) { $tmp = $_-> dequeue } # # my $tmp; $tmp = $_-> dequeue for $q; # # $q-> dequeue; $q-> dequeue; # # $q-> dequeue; # # my $tmp = $q-> dequeue; # 2 # my $tmp; if ( 1 ) { $tmp = $q-> dequeue } # # my $tmp; do { $tmp = $q-> dequeue } # # ( my $tmp ) = map $_-> dequeue, $q; # # 1 while $q-> dequeue; # } say memory; __END__ 10,912 K 987,620 K 987,628 K
|
|---|