in reply to Does Perl have garbage collection mechanism and how it performs?
Unfortunately, the current (as of 5.8) state of the ithreads implementation in perl still has some bugs, and the garbage collection of scalars shared implicitely through a shared array seems to be one of them. I don't know the ins and outs of it, nor if or when it is likely to be cured. From what I've read elsewhere, the bug seems to be a "perl thing", rather than relating to any particular platforms.
You can, at least in my very crude imperical tests, slow down the rate of growth by using Thread::Queue as the mechanism for distributing your data to your threads, but it doesn't fix it completely.
use 5.008; use strict; use threads qw(yield); use threads::shared (); use Thread::Queue; use Time::HiRes qw(sleep); $|++; my $Q = new Thread::Queue; $Q->enqueue( 1 .. 1000 ); my $sub1 = sub { my $a; while (1) { $Q->dequeue; yield; } }; my $t1 = new threads $sub1; my $t2 = new threads $sub1; my $t3 = new threads $sub1; $t1->detach; $t2->detach; $t3->detach; while(1) { # readFile(); # ... $Q->enqueue(1..1000) unless $Q->pending; print $Q->pending; yield; }
The other possibility, and it's not a good one, is to not detach your threads, but rather to occasionally join them and spawn a new one to replace it. The leaked memory seems to be released back to the OS once the thread is joined. I can't offer you a good designed for this as I haven't yet worked one out for myself. This is a very unsatisfactory situation, and I wish it were not so.
I also wish that I had the ability to assist in fixing the problem but even if I understood enough to construct a patch, I see no way for me to participate in the process.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Does Perl have garbage collection mechanism and how it performs?
by Joost (Canon) on Jun 18, 2003 at 16:59 UTC | |
by BrowserUk (Patriarch) on Jun 18, 2003 at 18:08 UTC | |
by batkins (Chaplain) on Jun 19, 2003 at 14:33 UTC | |
by BrowserUk (Patriarch) on Jun 19, 2003 at 16:58 UTC | |
by BrowserUk (Patriarch) on Jun 21, 2003 at 07:47 UTC |