As a Perl developer, you shouldn't have to worry about such things. If you're building something that will be using up some large amounts of memory, and you want to be sure that memory is only used while you're in a certain chunk of code, scope that variable within that chunk of code:
sub my_sub {
my $variable;
...
}
# or
if ($some_condition) {
my $other_variable;
...
}
# $other_variable disappears when 'if' block exits!
In this example, $variable will disappear when you leave that subroutine. The memory will not be free'd in that your process's memory usage will decrease, but the memory it was using is now available to be claimed by other variables in your code.
Generally Perl's garbage collection is meant to keep the tasks of memory management away from you, so you don't have to worry about it. So long as you use strict, Perl will just about force you to declare your variables, which means you have the opportunity to scope them where they are appropriate, and let them disappear when you're done with them. You may wish to get your hands on some Perl books that talks about this in more detail, and I think it's been covered on the site a few times, so a Super Search may give you some more help.
Hope this answers your question.. | [reply] [d/l] [select] |