First, a suggestion: supply more information! Please read the section of the PerlMonks FAQ on "How do I post a question effectively?".
After poking through the Camel Book, esp. the pages (299-301 in my copy, which is the Sep 1996 version of the 2d edition), it says "When a block is exited, my variables are normally freed up." (italics mine). I suspect that means that for a loop like this:
foreach(@file){ open(my $fh, "<", "$file") or die "Could not open $file because $! +\n"; my @data = <$fh>; close($fh); } #memory used for @data gets garbage collected here
memory doesn't get garbage collected until after the comment (or at the fragments's die statement)
I understand this to mean that code like the fragment above and this would g/c in the same way
{ my @data; foreach(@file){ open(my $fh, "<", "$file") or die "Could not open $file becaus +e $!\n"; @data = <$fh>; close($fh); } }
added in update
My understanding would also imply that the memory used will be based on the largest file processed in the loop. Also, Perl doesn't return memory to the O/S until it exits, so the (kilo|mega|giga|tera|peta|exa)byte or so you've used to read the largest of the files is kept in Perl's hot little hands.end of addition
Of course, there is a non-zero chance I'm wrong, and totally in left field (US idiom meaning "my answer is not only wrong but inane.").
emc
Experience is a hard teacher because she gives the test first, the lesson afterwards.
In reply to Re: releasing memory from a loop in Windows
by swampyankee
in thread releasing memory from a loop in Windows
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |