内存泄漏 - ActiveSupport - 依赖项

时间:2017-05-19 15:02:38

标签: ruby-on-rails memory-leaks ruby-on-rails-5

我最近在我的应用程序中发现了一些内存泄漏。

进行正常的堆转储并分析显示:

object count (670282)
==============================
  95930  activesupport-5.0.2/lib/active_support/dependencies.rb:293
  92143  activerecord-5.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:111
  49151  activesupport-5.0.2/lib/active_support/core_ext/marshal.rb:4
  13439  activerecord-5.0.2/lib/active_record/attribute.rb:5
  13423  activerecord-5.0.2/lib/active_record/result.rb:123
  13422

High Ref Counts
==============================

  283240  activerecord-5.0.2/lib/active_record/result.rb:123
  201375  activesupport-5.0.2/lib/active_support/dependencies.rb:293
  67110  activerecord-5.0.2/lib/active_record/attribute_set/builder.rb:19

注意active_support依赖项的最高对象数及其高引用计数。它所指的方法是:

def require(file)
  result = false
  load_dependency(file) { result = super }
  result
end 

https://github.com/rails/rails/blob/5-0-stable/activesupport/lib/active_support/dependencies.rb#L293

任何人都知道这个方法在做什么以及为什么要保留这么多内存?

1 个答案:

答案 0 :(得分:0)

该行(特别是对super的调用)会收到在执行每require期间创建的所有对象的归属地。<​​/ p>

有人指出,因为它是执行Ruby代码的最后一行,但它被指责的对象根本不与Active Support相关:它们是&#39;解析您正在加载的所有其他Ruby脚本以及初始化任何C扩展的结果。

相关问题