You do not give enough information for us t suggest a solution. If youre using earlier than 5.8.1, there are some known problems with memory leaks, but unless you are using large quanities of shared variables and/or not taking precautions to minimized the nadvertant sharing of datastructures and code between your threads, 5.8.0 is also quite useable. If your using earlier than 5.8.0, you should definately upgrade.

Unfortunately, beyond the sage advice in liz's Things you need to know before programming Perl ithreads, it it quite difficult to try and write down all the things that you need to look for that might be contributing to memory leaks in threaded apps. I know, because I've tried a couple of times. However, it is usually possible to eliminate (or reduce to a trivial minimum), the rate of leakage, but carefully working through the application looking for where things might be inadvertantly being shared in a way that makes it difficult for perl to clean up.

One thing that you probably shouldn't be doing is creating and destroying threads on a one-shot basis. It is hugely more efficient and creates much fewer possibilities for leaks, to create a pool of threads and dispatch elements of work to them via a queue. It's a somewhat harder way to use threads and would probably mean a fair amount of reworking of your existing application (going by the format of the snippet you posted), but the end result is usually worth the work.

Sorry to answer in the generic, but in the absence of more information, it is all that is possible.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!


In reply to Re: Threads Problem! by BrowserUk
in thread Threads Problem! by Anonymous Monk

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.