Created
March 8, 2015 06:29
-
-
Save mboeh/83338a4e3a6a77689e22 to your computer and use it in GitHub Desktop.
symbol-gc.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Garbage-collected symbols get new object IDs in Ruby 2.2.