A lot of the above comments seem to be missing something, though I confess I had to read the question a few times to really see the issue -- it's not about whether memory gets released back to the OS.
The 5.8.6 version of the FAQ seems to claim that the memory reserved for lexicals during a given run is released back to the interpreter when they go out of scope, and other lexicals later can use that recycled memory.
The 5.8.8 version of the FAQ seems to suggest that once you reserve memory for a lexical, it always belongs to that lexical, even after it goes out of scope. In other words, the more different lexicals you have in your code -- even if they aren't ever in the same scope -- the more memory your program will use.
In other words, the implication is that given this code:
sub one { my $large_struct = get_1MB_from($dbh); do_stuff_on(\$large_struct); } sub two { my $other_struct = get_1MB_from($dbh).get_1MB_from($dbh2); do_stuff_on(\$other_struct); } one; two;
As the FAQ is written for 5.8.6, the application would end up consuming 2MB of memory (+overhead, of course) as a result of the declared lexicals: 1MB gets allocated inside one(), then released to perl, then 2MB gets allocated inside two().
According to the 5.8.8 wording, the same code would take 3MB: 1MB gets allocated inside one(), and perl hangs on to it, even though the lexical has gone out of scope. When two() is called, that 1MB is still reserved "just in case" one() is called again, and an additional 2MB gets allocated.
That's what the docs appear to say: if it's really the case, then using lexicals could actually hurt applications that need to be careful about memory, and this would encourage developers not to trust perl to do the memory management, instead trying to do it themselves with globals.
That would, frankly, piss me off a bit. So, those who are perl internal gurus, what does 5.8.8 really do when a lexical goes out of scope?
In reply to Re: perl memory re-usage
by radiantmatrix
in thread perl memory re-usage
by mreece
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |