hashie/hashie

Memory leak possible

huacnlee opened this issue · 5 comments

By use derailed_benchmarks

$ PATH_TO_HIT=/topics/21 bundle exec derailed exec perf:objects
Endpoint: "/topics/21"
Total allocated: 730954 bytes (6620 objects)
Total retained:  4440 bytes (22 objects)

.....

retained memory by gem
-----------------------------------
      4360  hashie-5.0.0
        80  activesupport-7.0.4

retained memory by file
-----------------------------------
      4360  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/hashie-5.0.0/lib/hashie/mash.rb
        80  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/current_attributes.rb

retained memory by location
-----------------------------------
      4200  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/hashie-5.0.0/lib/hashie/mash.rb:196
       160  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/hashie-5.0.0/lib/hashie/mash.rb:391
        80  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/current_attributes.rb:213

retained memory by class
-----------------------------------
      4200  OmniAuth::Strategy::Options
       160  Hashie::Array
        80  Hash

retained objects by gem
-----------------------------------
        20  hashie-5.0.0
         2  activesupport-7.0.4

retained objects by file
-----------------------------------
        20  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/hashie-5.0.0/lib/hashie/mash.rb
         2  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/current_attributes.rb

retained objects by location
-----------------------------------
        16  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/hashie-5.0.0/lib/hashie/mash.rb:196
         4  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/hashie-5.0.0/lib/hashie/mash.rb:391
         2  /Users/jason/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/activesupport-7.0.4/lib/active_support/current_attributes.rb:213

retained objects by class
-----------------------------------
        16  OmniAuth::Strategy::Options
         4  Hashie::Array
         2  Hash

Did you close this because you saw that it's the way OmniAuth uses Hashie that may cause the leak?

I believe that neither of the stated lines will leak since they are for duplicating and wrapping values.

Yes, looks like it's by OmniAuth, so I closed before your reply.

In config/initializers/devise.rb if I disable the omniauth, the leaks gone.

Devise.setup do |config|
  # config.omniauth :github, setup: GITHUB_OMNIUATH_SETUP
  # config.omniauth :twitter, setup: TWITTER_OMNIAUTH_SETUP
  # config.omniauth :wechat, setup: WECHAT_OMNIAUTH_SETUP
end

Feel free to open an issue in omniauth/omniauth, but I likely will not have time soon to dig into it

@BobbyMcWho I have create open issue to OmniAuth project.

omniauth/omniauth#1097