in reply to A Memory Leak in Perl iThreads?

I don't think you're experiencing a leak per se.

On my iBook starting 100 threads without loading any additional Perl modules apart from "use threads" costs more than 31 Mbyte of memory. You might want to check this for yourself with my Benchmark::Thread::Size module like this:

$ perl -MBenchmark::Thread::Size=refonly # (ref) + 0 1728 1 2101 2 2398 5 3288 10 4780 20 7753 50 16685 100 31572
Your sample code seems to want to start 1000 threads. Be prepared to have at least 315 Mbyte of memory available for that. Unfortunately, in my experience, any serious program very quickly takes at least 1 Mbyte per thread. So you better have a lot of RAM available if you want to start 1000 threads that way.

You might also be interested in an article that I wrote about this earlier.

Liz

Replies are listed 'Best First'.
Re: Re: A Memory Leak in Perl iThreads?
by cav (Initiate) on Mar 21, 2004 at 15:13 UTC
    Even though the program seems to start many threads, it only keeps three threads open, joining the other threads, and even though the memory it uses keeps going up and up. Try to copy and paste the code in your PC and watch your memory go up even though you are only with 4 threads open.
    Thanks,
    Paulo C.
      Change:
      $thr{"FREE_HOST"} = threads->create("blast_thread");
      to:
      threads->create("blast_thread"); $thr{"FREE_HOST"} = 1;
      Seems you've stumbled on yet another way to make threaded Perl leak. Judging by the amount of memory leaked, it would seem that your way of doing it, doesn't release the memory used by the thread.

      I'll be filing a bug report for this to p5p. Until then, I would say: don't do it that way. Why aren't you using a shared scalar for the flag?

      Also, if you want to check whether a thread is still running, you might want to check out Thread::Running. And possibly Thread::Pool might also be of interest to you.

      Liz

        Liz, Thanks.. I have to use a hash since I am controling many computers, and each key of my hash controls a computer. Therefore, when the node returns, I need to know its done so I can send more work. I will check out the modules sugested. I was really worried if there was something wrong with my code but as you mentioned, it really seems to be a leak in the perl threads...If there is any other work around please keep me posted,
        Thanks,
        Paulo Carvalho