我最近从 ruby 1.8.7 (p371) 切换到 ruby 1.9.3 (p429),并观察到高内存泄漏(?)。由于内存耗尽,我的长时间运行的脚本最终都被杀死了。尝试使用一些分析器(rubyprof、memprof、bleakhouse 等)进行追踪,但似乎它们对 1.9.3 没有很好的支持。刚刚使用 valgrind 从 C 级别跟踪内存使用情况并观察到高泄漏,我运行以下示例代码:
A = ['na', 'ns', 'n/a.jpg']
b = 'N/A.jpg'
if A.include?(b.downcase)
puts 'yes'
end
很简单。在 ruby 1.8.7 中,我尝试了 valgrind --partial-loads-ok=yes --undef-value-errors=no --leak-check=full ruby test.rb,结果如下:
LEAK SUMMARY:
==28315== definitely lost: 0 bytes in 0 blocks
==28315== indirectly lost: 0 bytes in 0 blocks
==28315== possibly lost: 16,464 bytes in 431 blocks
==28315== still reachable: 15,103,747 bytes in 110,826 blocks
==28315== suppressed: 0 bytes in 0 blocks
在 1.9.3 中,它给出了以下结果:
LEAK SUMMARY:
==28228== definitely lost: 2,028,264 bytes in 9,246 blocks
==28228== indirectly lost: 1,221,720 bytes in 23,812 blocks
==28228== possibly lost: 21,251 bytes in 432 blocks
==28228== still reachable: 754,268 bytes in 15,849 blocks
==28228== suppressed: 0 bytes in 0 blocks
我观察到 rb_longjmp、rb_is_eq_eval、rb_class_new_instance、rb_ary_each.... 方法中的泄漏。这是否意味着 ruby 1.9.3 有泄漏?有什么办法解决吗?