in reply to releasing memory from a loop in Windows
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: releasing memory from a loop in Windows
by ikegami (Patriarch) on Aug 07, 2006 at 20:33 UTC | |
by Jenda (Abbot) on Aug 07, 2006 at 21:47 UTC | |
by BrowserUk (Patriarch) on Aug 07, 2006 at 22:06 UTC | |
by ikegami (Patriarch) on Aug 07, 2006 at 23:07 UTC |