As I suspected it (and Corion called it), you constantly start new threads and never join or detach them, then they just hang around consuming memory once they've completed.
Also, as the last line of the thread sub is $rss, that is returned from the thread, consuming more memory. The fact that you've shared it, as well as returning it means you've consumed even more.
And while I'm critiquing, there are some other anomalies in your code:
- "x" x (1024 * 1024 * 20) is a single string of 20MB 'x's.
The join is utterly redundant.
- return unless $rss;
Return (nothing) unless $rss has some value.
Otherwise, just fall off the end of the subroutine and return ???
Try something like this (untested):
#! perl -slw
use strict;
use threads;
use Win32::GUI qw();
use LWP::UserAgent;
sub t {
my $rss;
my $ua = LWP::UserAgent->new;
my $response = $ua->get(
'http://www.mektek.net/mekmatch/listServersRss.mkz'
);
$rss = $response->decoded_content
if $response->is_success;
print "done1";
return $rss;
}
my $window = Win32::GUI::DialogBox->new(
-title => "Test", -name => "Test", -onTimer => sub { return poll()
+ }
);
my $use_up_some_memory = join( "", "x" x (1024 * 1024 * 20) );
$window->AddTimer( "T1", 5000 );
$window->Show;
Win32::GUI::Dialog();
sub poll
{
print "polling ... ";
my $thread = threads->create( \&t );
while ( $thread->is_running ) {
Win32::Sleep 10;
Win32::GUI::DoEvents;
}
print " done2";
return $thread->join;
}
Presumably you want to do something with the data returned from poll?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|