From: Rob Doug Date: 2009-10-21T07:47:07+09:00 Subject: Re: memory leak > As far as I can see you're never cleaning Array threads. You are just > appending to the Array and so even terminated threads will stay in there > because you also do not reuse threads. > > Design criticism: usually you create threads upfront and pass work to > them via a Queue then you don't need the sleep crutch and use blocking > instead. Also, you can make your code better handle large volumes of > URLs by using a more streamed approach along the lines Ryan presented by > limiting all resources (not only threads but also size of the queue). > > require 'thread' > ... > > THREADS = 50 > q = SizedQueue.new(THREADS * 2) > > threads = (1..THREADS).map do > Thread.new q do qq > until qq.equal?(url = qq.deq) > Common.... > end > end > end > > File.foreach("bases/3+4.txt") do |line| > line.chomp! > q.enq(URI.parse(line)) > end > > threads.size.times {|q| q.enq q} Very thank you, your solution is great. Code become much clear and looks good. :) But, this is not solve memory leak :( Any ideas or suggestions? -- Posted via http://www.ruby-forum.com/.