Last active
December 10, 2015 22:29
-
-
Save bachue/4502552 to your computer and use it in GitHub Desktop.
A test to prove Symbol can't be GC in both Ruby 1.9 and Ruby 1.8
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
MAX_LENGTH = 10 | |
def generate(base_str) | |
[('a'..'z'), ('A'..'Z'), ('0'..'9')].map(&:to_a).flatten.each do |char| | |
str = base_str + char | |
str.to_sym # You can comment this statement and compare the result | |
generate(str) if str.size <= MAX_LENGTH | |
end | |
end | |
main = Thread.start { | |
generate('') | |
Thread.kill(counter) | |
puts 'generating is over ...' | |
} | |
counter = Thread.start { | |
loop do | |
GC.start # GC here to free memery | |
puts "Current number of Objects: " + ObjectSpace.each_object(Object).count.to_s | |
sleep 1 | |
end | |
} | |
counter.join | |
main.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment