Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Memory Leak

by boom (Scribe)
on Feb 20, 2009 at 04:39 UTC ( [id://745272]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://745272]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found