English 中文(简体)
script script consumption consumption consumption consumption ......
原标题:ruby script memory % consumption keeps going up...any way to prevent this?

i 操作我的手法,这是一个很长的 lo。 每一 lo,一些随机的html文档都通过Nokogiri进行。

顶端显示,记忆消耗量百分比与每几秒钟的 c用量相比,正在增加0.1。

最终,由于“记忆不足”而使废墟碎打。

附文:

def extract(newdoc, newarray)
 doc = Nokogiri::HTML(newdoc) 
 collection =   
 collection = newarray.map {|s| doc.xpath(s)}
 dd = ""; 


(0...collection.first.length).each do |i|
    (0...collection.length).each do |j|
      dd += collection[j][i].to_s
    end
end
 collection =   
 newarray =   
 doc =   
 puts dd.chop + "
"

end

for 1..100000
extract("somerandomHTMLfile", ["/html/body/p", "/html/body/h1"])
end
问题回答

我不理解你如何主持你的收集工作。 我将改写如下:

collection.each do |coll_of_fields|
  coll_of_fields.each do |field|
    spliceElement(field, dd)
  end
  newrow = dd.chop() + "
" 
end

现在,你似乎认为,每个阵列中至少有一阵列的许多内容。 为什么不首先 over倒所有各行,然后是一行中的所有内容?

另外,<代码>回到新行<>对我来说还不清楚? 你们在第一次穿过外lo之后就停止了吗?

为什么在你通过一个参数的原始阵列中,你不使用<代码>/html/上/h1/text()?

接着,你ice子 内容只能直接进行。 还是缺少东西?

根据你的其他问题,我很想知道,你是否节省了<编码>extract的价值,或者以某种其他方式保留在的提及上。 我假定你每次都想开始吗?

无论如何,在你的其他问题中,似乎仍然有一些编辑。 你应该肯定地确定,你不想在周期之间保持沉默。

如果这还不够好,你可能需要按照你的逻辑进行二元搜索,并且将你方案的一半分到一套相互交织的假体,直到你看到发生记忆损失的地方。

各位可在每一节选之后打电话GC.start/code>,明确开始收集垃圾并清理未使用的记忆。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...