I'm puzzled by something that seems simple, but yet is yielding strange results. I'm using threading as part of a decent sized program, the easiest way to describe the purpose of this code is it's part of an alarm system.
What I'm running into is a memory leak when using ithreads, sleep, and detach. This doesn't seem to happen if I use join to wait for the thread to finish execution, but I can't do this because the main loop has to keep running.
Here is a short snippet of code that exhibits the issue, the modules are in there for two reasons, one being it shows the leak better, two being these are what are used in the production code.
use Email::Sender::Simple qw(sendmail);
chomp(my $msg = $_);
print "Received: $msg\n";
if ($msg =~ /start/)
my $thread = threads->create(\&thread);
print "Thread started!\n";
I'm using PERL 5.20.2, compiled using perlbrew. I'm using top and ps to watch memory usage on a Linux server. Type "start" a few times and the memory usage balloons about 6MB each time. At random points the ballooning stops, and PERL will reclaim seemingly about 1MB of memory, then start ballooning again.
What am I missing here?