The biggest thing you can do is start using strict.pm to catch when you use globals, and use lexical variables (declared with my) everywhere. This should result in having all uses of data tightly scoped, giving Perl a clean point to drop it.

After that look for an ever increasing arrays or self-referential data structures. There are also some internal Perl leaks (eg anonymous functions are not currently freed.) A useful tool for tracking down that kind of thing is Devel::Leak.

When I have had to track this kind of thing down in the past, I have done things like override bless (see perlsub to learn how to do this) so that I kept track of caller information about object assignment, then I had a UNIVERSAL::DESTROY method that would catch when the objects went away. This gave me pretty complete information on where things that weren't getting freed were being assigned. (And with this idea you can fine-tune things to only get the packages you are interested in.)

That is a little tricky though. Most of the time you will get it just by being strict.pm and making all of your variables tightly scoped.


In reply to Re (tilly) 1: memory usage/leaks by tilly
in thread memory usage/leaks by smackdab

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.