memory leak in I18n::Backend::Cascade #160

Closed
TauPan opened this Issue Aug 30, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@TauPan

TauPan commented Aug 30, 2012

This code (test.rb)

require 'i18n'
I18n::Backend::Simple.send(:include, I18n::Backend::Cascade)
module I18n
  class << self
    alias_method :translate_old, :translate
    def translate_with_cascade(key, options = {})
      translate_old(key, options.merge(:cascade => true))
    end
    alias_method :translate, :translate_with_cascade
    alias_method :t, :translate
  end
end

I18n.backend.load_translations('en.yml')

while true
  puts I18n.t(:'foo.gna.wagga.dudel.baz')
end

With the following localisations: (en.yml)

en:
  foo:
    bar:
      baz: 'quz'
    baz: 'bazz'

will leak about a megabyte virtual memory every 3-4 seconds on my machine (ruby 1.9.2-p320).

@TauPan

This comment has been minimized.

Show comment Hide comment
@TauPan

TauPan Aug 30, 2012

scope gets modified with slice! after being commited to normalized_key_cache, which is definitely not so good... obvious fixes (like adding .dup or .clone after scope = I18n.normalize_keys(nil, key, scope, separator)) fail for me.

TauPan commented Aug 30, 2012

scope gets modified with slice! after being commited to normalized_key_cache, which is definitely not so good... obvious fixes (like adding .dup or .clone after scope = I18n.normalize_keys(nil, key, scope, separator)) fail for me.

@TauPan

This comment has been minimized.

Show comment Hide comment
@TauPan

TauPan Aug 30, 2012

Code that could go into a test case:

require 'i18n'
I18n::Backend::Simple.send(:include, I18n::Backend::Cascade)
module I18n
  class << self
    alias_method :translate_old, :translate
    def translate_with_cascade(key, options = {})
      translate_old(key, options.merge(:cascade => true))
    end
    alias_method :translate, :translate_with_cascade
    alias_method :t, :translate
  end
end

I18n.backend.load_translations('en.yml')

puts I18n.t(:'foo.gna.wagga.dudel.baz')
GC.start
orig = ObjectSpace.count_objects[:T_ARRAY]

while true
  puts I18n.t(:'foo.gna.wagga.dudel.baz')
  GC.start
  puts ObjectSpace.count_objects
  puts "lost: %s" % [ObjectSpace.count_objects[:T_ARRAY] - orig]
end

TauPan commented Aug 30, 2012

Code that could go into a test case:

require 'i18n'
I18n::Backend::Simple.send(:include, I18n::Backend::Cascade)
module I18n
  class << self
    alias_method :translate_old, :translate
    def translate_with_cascade(key, options = {})
      translate_old(key, options.merge(:cascade => true))
    end
    alias_method :translate, :translate_with_cascade
    alias_method :t, :translate
  end
end

I18n.backend.load_translations('en.yml')

puts I18n.t(:'foo.gna.wagga.dudel.baz')
GC.start
orig = ObjectSpace.count_objects[:T_ARRAY]

while true
  puts I18n.t(:'foo.gna.wagga.dudel.baz')
  GC.start
  puts ObjectSpace.count_objects
  puts "lost: %s" % [ObjectSpace.count_objects[:T_ARRAY] - orig]
end
@TauPan

This comment has been minimized.

Show comment Hide comment
@TauPan

TauPan Aug 31, 2012

Meanwhile I can confirm that this fixes the memory hemorrhaging in our rails app. It's still slow for other reasons, but it's not getting slower with every request. :-)

TauPan commented Aug 31, 2012

Meanwhile I can confirm that this fixes the memory hemorrhaging in our rails app. It's still slow for other reasons, but it's not getting slower with every request. :-)

svenfuchs added a commit that referenced this issue Aug 31, 2012

Merge pull request #161 from TauPan/fix-cascade-memory-leak
make sure, already cached scope is not modified, fixes issue #160
@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva May 7, 2014

Collaborator

Related PR #161 has been merged, closing the issue.

Collaborator

carlosantoniodasilva commented May 7, 2014

Related PR #161 has been merged, closing the issue.

atzorvas pushed a commit to e-travel/i18n that referenced this issue Jan 12, 2016

Merge pull request #160 from Holek/patch-1
[Polish] missed diacritic in abbreviated name for Friday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment