Created
December 8, 2020 05:50
-
-
Save RashneetR/c6c505d548dc1a453815799bc67c8dd4 to your computer and use it in GitHub Desktop.
Garbage collection Example with Ruby Version
This file contains 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
# This script shows how garbage collection is done for symbols Ruby 2.2.1 onwards | |
# Ruby 2.1 | |
100_000.times do |i| | |
"sym_#{i}".to_sym | |
end | |
# => 100000 | |
before = Symbol.all_symbols.size | |
# => 103318 | |
GC.start | |
# => nil | |
after = Symbol.all_symbols.size | |
# => 103318 | |
# Ruby 2.2.1 | |
before = Symbol.all_symbols.size | |
# => 3892 | |
100_000.times do |i| | |
"sym_#{i}".to_sym | |
end | |
# => 100000 | |
before = Symbol.all_symbols.size | |
# => 5535 | |
GC.start | |
# => nil | |
after = Symbol.all_symbols.size | |
# => 3892 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment