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:
use threads;
use strict;
use warnings;
for (;;) {
my $thr = threads->new($sub1)->join;
undef $thr;
}
I'm monitoring rss usage on linux and perl 5.10 using:
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
Here's the output of this, with different values of $sub1:
# $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
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