Skip to content

Instantly share code, notes, and snippets.

@mboeh
Created March 8, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mboeh/83338a4e3a6a77689e22 to your computer and use it in GitHub Desktop.
Save mboeh/83338a4e3a6a77689e22 to your computer and use it in GitHub Desktop.
symbol-gc.rb
puts "Ruby version: #{RUBY_VERSION}"
def show_a_sym(sym)
puts "sym #{sym} = #{sym.object_id}"
end
def pick_a_sym
a = (1..100_000).map{|s| :"dummy-#{s}" }
sym = a.sample
show_a_sym sym
sym.to_s.gsub(/dummy-/, '').to_i
end
def make_a_sym(i)
show_a_sym :"dummy-#{i}"
end
i = pick_a_sym
make_a_sym i
GC.start
make_a_sym i
@mboeh
Copy link
Author

mboeh commented Mar 8, 2015

Garbage-collected symbols get new object IDs in Ruby 2.2.

Ruby version: 2.2.1
sym dummy-23284 = 14517920
sym dummy-23284 = 14517920
sym dummy-23284 = 9494360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment