Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Perl won't release memory back to the operating system at runtime, only on global destruction as the script terminates. However, Perl will re-use the memory that it has allocated and that it is no longer using. For example, if you declare a lexical variable in one scope and load it up with 30MB of data, but then let that variable fall out of scope, Perl should be able to re-use that memory space.

Places to look:

  • Circular references: These can cause memory leaks since the memory never has its reference count drop to zero, Perl can't re-claim it for internal use.
  • Modules: Are you using half of CPAN? There's nothing wrong with using Moose, DBIx::Class, and many of the other slightly heavy distributions on CPAN, but they do use memory.
  • Scoping: Are you allowing lexical variables to fall out of scope? (You should be.) Program with the objective of keeping state as ephemeral as possible; let variables have the narrowest possible scope - particularly those that are holding large chunks.
  • File/Database handling: Are you slurping in large files or large Database query data sets? Process smaller chunks at a time.
  • Stability: Once your process grows to 30MB, does it stay there, or does it grow further over time? Frankly, even if it's consuming 100MB, that's not the end of the world as long as you can count on it staying close to that plateau. If it keeps on growing over time, you've got a bigger problem (a memory leak). A well-behaved process that hits a memory plateau and stays there is usually acceptable.
  • Tools: Try valgrind, Devel::LeakTrace, Devel::MemoryTrace::Lite, and other such tools can help you to watch how memory is growing and being used.

Dave


In reply to Re: Perl Memory problem ... by davido
in thread Perl Memory problem ... by Sascha2018

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-29 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found