hi ppl,

well as the title says i need some help with this bug i'm having. or should i say, just an indication of what could be the problem. so i have this program that constantly waits for a std input to do something (regular while loop). depending on an input i runs some procedure and it can do it as many times as user wishes it with constant memory usage, because every time the memory is cleaned:

pseudo code or something just to illustrate what the code is doing use strict; my %hs1; #... $| =1; while(1){ chomp(<>); do something to fill %hs1 if ($_=~/X/); sleep 5; %hs1 = (); }
so the other day my boss comes to me and says: "How do i know that the program didn't froze while i'm waiting for a result, i don't! you have to make this visible somehow...." so i said ok. ( the process that fills the %hs1 is quite long due to extensive calculations it does. (arbitrary precision calculations (with a cutoff) are preformed, so it can take up to some 2-200 min )). since i can't predict how many steps the algorithm is going to do (for some regular progress bar) i decided to trick him by creating an extra thread, detach it, and make a while loop that runs continuously until some thing stops it. in this case the check-point is a finish status(when process is done).(please don't judge me i know that circling around the truth isn't the best way to go, but it's just a quick fix until i get some time to do it properly :) ) :
use strict; use threads; use threads::shared; share(my $var); #some other hashes not shared; my %hs1; #... $| =1; while(1){ chomp(<>); _progress(); do something to fill %hs1 if ($_=~/X/); _stop(); sleep 5; %hs1 = (); } sub _progress { threads->new(\&_status)->detach; } sub _status { my $count = 0; while($var){ my $bar; if ($count == 10){ $bar = '' ; $count = 0; } $bar .= '>' print "\r$bar"; $count++; sleep 1; } } _stop { $var = 0; }
so where is the problem : when i implement the threads, the memory is just getting larger every time i go through the main while loop. maybe this example doesn't illustrate the problem quite accurately but in the real example when i remove the threading everything is ok. my question is : does somebody sees why the threading would cause the memory leakage? (implementation of the threading model is accurately described within the example )

thank you for reading this long post!

UPDATE:

THNX zwon, sadly you found the problem !


In reply to [threads]memory leak - help needed with debugging by baxy77bax

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.