faxm0dem has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm having huge memleaks using threads;
I came upon node_id=625622, which has no conclusion.
Here's the thing: running the following code uses up more and more memory, but quite unpredictably depending on the contents of $sub1:
I'm monitoring rss usage on linux and perl 5.10 using:use threads; use strict; use warnings; for (;;) { my $thr = threads->new($sub1)->join; undef $thr; }
Here's the output of this, with different values of $sub1:i=0; while :; do A=$(ps -C threads3 -o ppid,pid,cmd,rss --no-headers); + [ -n "$A" ] && echo $i $A || i=0 ; sleep 1; i=$(($i+1)); done
Any idea what's happening here? $sub1 = sub { my $a= 1 .. 100000 } seems to have minor memleak, while an empty sub does the most damage... I tried using 'forks' instead, which seems to solve the problem. PS: The code proposed by BrowserUk in 625622 also leaks# $sub1 = sub { my $a=[ 1 .. 10000] }; 1 19959 1137 /usr/bin/perl ./threads3 5276 2 19959 1137 /usr/bin/perl ./threads3 5140 3 19959 1137 /usr/bin/perl ./threads3 5700 [...] 642 19959 1137 /usr/bin/perl ./threads3 124244 643 19959 1137 /usr/bin/perl ./threads3 124736 644 19959 1137 /usr/bin/perl ./threads3 125380 # $sub1 = sub { my $a=[ 1 .. 100000] }; 1 19959 8329 /usr/bin/perl ./threads3 24176 2 19959 8329 /usr/bin/perl ./threads3 24176 3 19959 8329 /usr/bin/perl ./threads3 24176 [...] 642 19959 8329 /usr/bin/perl ./threads3 28368 643 19959 8329 /usr/bin/perl ./threads3 26036 644 19959 8329 /usr/bin/perl ./threads3 34460 # $sub1 = sub { }; 1 19959 13288 /usr/bin/perl ./threads3 3152 2 19959 13288 /usr/bin/perl ./threads3 3796 3 19959 13288 /usr/bin/perl ./threads3 4564 [...] 642 19959 13288 /usr/bin/perl ./threads3 400640 643 19959 13288 /usr/bin/perl ./threads3 401312 644 19959 13288 /usr/bin/perl ./threads3 401980
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: does threads (still) memleak?
by BrowserUk (Patriarch) on Nov 17, 2008 at 11:16 UTC | |
by weismat (Friar) on Nov 17, 2008 at 12:54 UTC | |
by Anonymous Monk on Nov 18, 2008 at 02:36 UTC | |
by BrowserUk (Patriarch) on Nov 18, 2008 at 02:51 UTC | |
Re: does threads (still) memleak?
by zentara (Archbishop) on Nov 17, 2008 at 13:53 UTC | |
by faxm0dem (Novice) on Nov 21, 2008 at 12:48 UTC | |
by zentara (Archbishop) on Nov 21, 2008 at 13:38 UTC | |
by BrowserUk (Patriarch) on Nov 21, 2008 at 14:20 UTC | |
by zentara (Archbishop) on Nov 21, 2008 at 17:01 UTC | |
by faxm0dem (Novice) on Nov 24, 2008 at 13:16 UTC | |
by BrowserUk (Patriarch) on Nov 24, 2008 at 13:55 UTC | |
| |
by zentara (Archbishop) on Nov 24, 2008 at 15:55 UTC |
Back to
Seekers of Perl Wisdom