Skip to content

Instantly share code, notes, and snippets.

@Edouard-chin
Last active April 25, 2019 21:11
Show Gist options
  • Save Edouard-chin/a1b5d86b584c1f00090599e0360844eb to your computer and use it in GitHub Desktop.
Save Edouard-chin/a1b5d86b584c1f00090599e0360844eb to your computer and use it in GitHub Desktop.
Weird
# frozen_string_literal: true
require 'psych'
class Foo
def value
return @value if defined?(@value)
@value = {
fix_encoding('foo') => fix_encoding('a' * 24),
fix_encoding('bar') => fix_encoding('b' * 24),
}
end
def forgetting_assignment
Psych.dump(value)
end
def fix_encoding(string)
string.encode(Encoding::ASCII).gsub(/bla/i, '')
end
end
4.times { GC.start }
GC.disable
before_last_change = Foo.new
before_last_change.forgetting_assignment
p before_last_change.value
4.times { GC.start }
p before_last_change.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment