From: Eleanor McHugh Date: 2009-03-18T01:14:44+09:00 Subject: Re: free RAM problem On 17 Mar 2009, at 15:23, Edouard Dantes wrote: >> Without seeing code it's hard to comment, > > Thanks for answer, > > well, the loops are too basic to create problems, it's fill array with > values & write to file. > > RAM jumps are too erratic (5 or 10% for 2GB RAM) > > The only processor angry stuff (and possibly RAM too) is the following > parsing line, imported from another file. > > Nokogiri::HTML(page).css('div a').map{|dts| > dts.text.gsub(/\s+/,"").gsub(/[^A-Za-z0-9\s]/,'Z') } > > This line runs thousands of time, might the implied regex feed RAM > with > datas without cleaning? I'm not sure it'll make much difference but moving the regex creation into the enclosing scope seems neater: spaces = /\s+/ chars = /[^A-Za-z0-9\s]/ Nokogiri::HTML(page).css('div a').map { |dts| dts.text.gsub(spaces, "").gsub(chars, 'Z') } Likewise changing the logic to use gsub! will reduce the number of transient string objects being created and that will reduce memory usage. I'd also be interested to see the code you're using for writing to file as the nature of the RAM usage jumps suggests you could be experiencing a buffering artefact. Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason