in reply to Re^2: Tracking down memory leaks
in thread Tracking down memory leaks
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Tracking down memory leaks
by Hena (Friar) on Apr 13, 2005 at 13:22 UTC | |
by Joost (Canon) on Apr 13, 2005 at 14:13 UTC | |
|
Re^4: Tracking down memory leaks
by Anonymous Monk on Apr 13, 2005 at 15:09 UTC |