小编roc*_*egg的帖子

Ruby 2.1.7 vs 2.2.3垃圾回收

我正在看到一些奇怪的潜在红宝石2.2.3 gc相关问题,从单词列表生成前缀尝试.可疑代码在这里:

def insert(word)
      return if word.nil? || word.empty?
      node = self
      counter = 0
      l = word.length
      #TODO _ why is this not being garbage collected?
      word.bytes.each do |i|
        counter += 1
        node.children[i] ||= Node.new(i.chr, node, counter == l)
        node = node.children[i]
        node.terminal = true if counter == l
      end
    end
Run Code Online (Sandbox Code Playgroud)

它是从字符串列表中调用的 - 就这样

words.each_with_index do |word, i|
    @root.insert(word)
Run Code Online (Sandbox Code Playgroud)

当我对此进行一些内存分析时,我看到ruby 2.2.3-railsexpress中的总mem用量为~68MB:

Measure Mode: memory
Thread ID: 70102347546980
Fiber ID: 70102348363420
Total: 68688.375000
Sort by: self_time

 %self      total      self …
Run Code Online (Sandbox Code Playgroud)

ruby garbage-collection memory-leaks

5
推荐指数
0
解决办法
158
查看次数

标签 统计

garbage-collection ×1

memory-leaks ×1

ruby ×1