in reply to ithreads memory leak

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 happens if you recast the code as follows?:

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; }

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.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^2: ithreads memory leak
by DNAb (Novice) on Apr 08, 2015 at 18:03 UTC

    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.

      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.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
        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.