boom has asked for the wisdom of the Perl Monks concerning the following question:

Is it necessary to consider about memory leak while writing a Perl program?

Replies are listed 'Best First'.
Re: Memory Leak
by tilly (Archbishop) on Feb 20, 2009 at 05:16 UTC
    Perl uses reference counting to free memory appropriately. So usually things work and you don't get memory leaks. However if you create circular references (eg A refers to B refers to C refers to A), it is up to you to manually break the circle so that they can all get freed.
Re: Memory Leak
by eye (Chaplain) on Feb 20, 2009 at 08:11 UTC
Re: Memory Leak
by bruno (Friar) on Feb 20, 2009 at 11:18 UTC
    If you suspect that your applications are leaking, I suggest you use Devel::Leak or Devel::Leak::Object to detect where the leakage is, and then Devel::Cycle to see where the circular references in the leaking variables/objects are.

    Here's a blogpost about detecting a leakage with these tools and fixing it by jrockway, and here's a bug report that I filed detecting a leakage in a module, also using these modules.

    If the circular references are there by design, they should be weakened, as pointed by eye.

Re: Memory Leak
by Anonymous Monk on Feb 20, 2009 at 11:33 UTC
    As long as you make sure you have closures for your variables it won't be a problem. Create as few global variables as possible, use "my $variable" and use strict;.

    The suggestions above are all good as well.