From: Rob Doug Date: 2009-10-20T23:29:32+09:00 Subject: Re: memory leak Ryan Davis wrote: > On Oct 19, 2009, at 18:10 , Rob Doug wrote: > >> threads.each { |t| >> unless t.status then >> t.join >> end >> } >> puts "total threads: " + Thread.list.size.to_s >> redo >> end >> end >> >> threads.each { |t| t.join() } > > I can't speak for your supposed "leaks" (pure ruby almost never has > leaks, but it does have many sneaky ways to make valid object > references that you can overlook), since I can't figure out what your > code does or how it is supposed to work. threads is an array of thread > objects that you only ever push on and you never clear or shift off > of. Also, why oh why oh why are you doing a redo??? Overly complicated > code may not be the source of your leak (and in this case it may very > well be), but it certainly isn't doing you any favors. > > I almost always structure my threads as a pool of workers pulling from > a queue of tasks: actually I had this kind of code at first: links.each do |link| if Thread.list.size < 50 then threads << Thread.new(link) { |myLink| Common.post_it(myLink,doorway) } else sleep(1) threads.each { |t| unless t.status then t.join end } threads = threads.delete_if {|t| t.status == false} GC.start redo end end but it does not help, and I reduce this code -- Posted via http://www.ruby-forum.com/.