内存泄漏 - 活动支持 - 依赖项



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

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

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

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

该行(特别是对super的调用(接收在执行每个require的过程中创建的所有对象的归属。

之所以指向它,是因为它是执行的 Ruby 代码的最后一行,但它被指责的对象与主动支持完全无关:它们是解析您正在加载的所有其他 Ruby 脚本以及初始化任何 C 扩展的结果。

相关内容

最新更新