Shouldn't these situations be handled by garbage collection.Maybe, but mostly they aren't, for performance reasons:
sub bla { my $arg = shift; my $big_string = $arg x 1000; }
Perl will in general keep the memory for $big_string allocated and reserved, because then it doesn't need to allocate the memory again next time the sub is called.
Explicitly undef()ing or resizing variables before they go out of scope sometimes helps, though - on some systems, it might even free the memory back to the system.
Usually, you don't need to do this, exactly because the memory gets reused anyway. If your program grows a lot, it's more likely you're using an inefficient algorithm, or you're creating circular references somewhere.
In reply to Re^3: Tracking down memory leaks
by Joost
in thread Tracking down memory leaks
by scain
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |