Having a slight problem with threads and perl and leaking memory.
Declaring a thread with
my $thr = threads->new(\&some_sub,$_);
$thr -> detach();
Inside a loop eventually crashes the program without any error message. I can see why as defining the thread with my means the next iteration could simply get wiped out, which is probably what happens.
@thr_ll[$used_threads] = threads -> new(\&some_sub,$_);
@thr_ll[$used_threads] -> detach();
Does not crash the program and seems to be stable after hours of use however it is quickly and consistently leaking memory (more or less 10 MB per iteration).
The subroutine some_sub can run for minutes or hours depending on how long the thread takes to run.
Any help on how to either: cleanup after the thread is finished (threads->exit() within the tread has no effect on leaking memory), not have my $thr overwrite it self, or your own custom solution would be greatly appreciated.