I played a bit with your code, and I just want to register my confusion on a couple of matters. First, on this:
foreach my $thr (threads->list) { # Don't join the main thread or ourselves if ($thr->tid && !threads::equal($thr, threads->self)) { $thr->join; } }

The main thread has an id of "0", and threads->list doesn't seem to return thread 0, so I wonder if that's a bug in the list() method, or if the conditional before the join is unnecessary.

Second, on this:

my $GetProcessMemoryInfo = Win32::API->new('psapi','GetProcessMemo +ryInfo', ['I', 'P', 'I'], 'I') or return $^E;
I thought it was a waste linking to that function on every call to it, so I tried to move it (and the other Win32::API function definition), to near the top of the program, but it ended up crashing perl. If I defined it near the top, and still defined it again on every call, it worked a couple of times, but then returned "The specified module could not be found" trying to link to it again after joining the threads.

In reply to Re: Cleaning up threads so they do not leak memory. (Win32) by runrig
in thread Cleaning up threads so they do not leak memory. (Win32) by slloyd

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.