Same effect unfortunately, to confirm my code now looks like:
#!/home/alerting/perl5/perlbrew/perls/perl-5.20.2/bin/perl
use warnings;
use IO::Handle;
use threads stack_size => 64*1024;
use strict;
use DBI;
use Email::MIME;
use Email::Sender::Simple qw(sendmail);
while (<STDIN>)
{
chomp(my $msg = $_);
print "Received: $msg\n";
if ($msg =~ /start/)
{
threads->create(\&thread)->detach;
}
}
sub thread
{
print "Thread started!\n";
sleep 5;
}
Memory usage still balloons, stops, then starts up again. Very puzzling, at least to me. | [reply] [Watch: Dir/Any] [d/l] |
I don't believe you are seeing a leak. I have to express it this way because I don't have *nix to test on; but running your code on my system, I see memory growth, but not a leak.
To confirm my findings, tweak your code so:
#!/home/alerting/perl5/perlbrew/perls/perl-5.20.2/bin/perl
use warnings;
use IO::Handle;
use threads stack_size => 64*1024;
use strict;
use DBI;
use Email::MIME;
use Email::Sender::Simple qw(sendmail);
while (<STDIN>)
{
threads->create(\&thread)->detach;
sleep 5;
}
sub thread
{
print "Thread started!\n";
sleep 4;
}
Essentially what that does is limit your program to using only child thread at a time. (Not useful in the real world, but good for testing.).
Run that and hold the enter key down while monitoring the memory usage and you should see an initial jump from circa 7MB to around 13MB, and then the memory usage should stay steady no matter how long you hold the key down for. Come back and let me know if that is true; and then I'll try and explain what you are seeing.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
| [reply] [Watch: Dir/Any] [d/l] |
With the above code the usage stays steady at 23MB, compared to the hundreds of MBs.
Certainly curious to hear how to deal with this, I will indeed need multiple child threads running. I thought that PERL should be doing garbage collection once the threads terminate.
| [reply] [Watch: Dir/Any] |