我正在看到一些奇怪的潜在红宝石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)